code relies on things done in a certain order
This makes sure that the code gets done in the order that is expected
This commit is contained in:
parent
4f6211ce50
commit
e219c1a33a
@ -140,9 +140,8 @@ router.patch(
|
|||||||
|
|
||||||
const withParents = body.filter((x) => x.parent_id !== undefined);
|
const withParents = body.filter((x) => x.parent_id !== undefined);
|
||||||
const withPositions = body.filter((x) => x.position !== undefined);
|
const withPositions = body.filter((x) => x.position !== undefined);
|
||||||
|
// You can't do it with Promise.all or the way this is being done is super incorrect
|
||||||
await Promise.all(
|
for await (const opt of withPositions) {
|
||||||
withPositions.map(async (opt) => {
|
|
||||||
const channel = await Channel.findOneOrFail({
|
const channel = await Channel.findOneOrFail({
|
||||||
where: { id: opt.id },
|
where: { id: opt.id },
|
||||||
});
|
});
|
||||||
@ -156,12 +155,10 @@ router.patch(
|
|||||||
channel_id: channel.id,
|
channel_id: channel.id,
|
||||||
guild_id,
|
guild_id,
|
||||||
} as ChannelUpdateEvent);
|
} as ChannelUpdateEvent);
|
||||||
}),
|
}
|
||||||
);
|
// Due to this also being able to change the order, this needs to be done in order
|
||||||
|
|
||||||
// have to do the parents after the positions
|
// have to do the parents after the positions
|
||||||
await Promise.all(
|
for await (const opt of withParents) {
|
||||||
withParents.map(async (opt) => {
|
|
||||||
const [channel, parent] = await Promise.all([
|
const [channel, parent] = await Promise.all([
|
||||||
Channel.findOneOrFail({
|
Channel.findOneOrFail({
|
||||||
where: { id: opt.id },
|
where: { id: opt.id },
|
||||||
@ -197,8 +194,7 @@ router.patch(
|
|||||||
channel_id: channel.id,
|
channel_id: channel.id,
|
||||||
guild_id,
|
guild_id,
|
||||||
} as ChannelUpdateEvent);
|
} as ChannelUpdateEvent);
|
||||||
}),
|
}
|
||||||
);
|
|
||||||
|
|
||||||
await Guild.update(
|
await Guild.update(
|
||||||
{ id: guild_id },
|
{ id: guild_id },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user