From 6eeed044eca2c516b91a78dc58bd8169b6b409af Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Wed, 13 Apr 2022 05:46:30 -0700 Subject: [PATCH] initialize server action states --- core/src/messages/servers/add.ts | 1 + core/src/plugins/actionStates.ts | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/core/src/messages/servers/add.ts b/core/src/messages/servers/add.ts index cf9a61fc6..c799b3a85 100644 --- a/core/src/messages/servers/add.ts +++ b/core/src/messages/servers/add.ts @@ -13,6 +13,7 @@ async function addServer(app: FastifyInstance, user: User, { server }: { server: } server.owners = [user.username]; const created = await app.servers.create(server); + app.serverActionStates.add(server._id!); addServerUpdate( app, created._id!, diff --git a/core/src/plugins/actionStates.ts b/core/src/plugins/actionStates.ts index 5a75cb0d8..dd16fc174 100644 --- a/core/src/plugins/actionStates.ts +++ b/core/src/plugins/actionStates.ts @@ -128,15 +128,6 @@ const actionStates = fp((app: FastifyInstance, _: {}, done: () => void) => { }, }); - app.builds.find({}, { _id: true }).then((builds) => { - builds.forEach((build) => app.buildActionStates.add(build._id!)); - }); - app.deployments.find({}, { _id: true }).then((deployments) => { - deployments.forEach((deployment) => - app.deployActionStates.add(deployment._id!) - ); - }); - app.decorate("serverActionStates", { getJSON: (serverID: string) => { return serverActionStates[serverID]; @@ -171,6 +162,18 @@ const actionStates = fp((app: FastifyInstance, _: {}, done: () => void) => { }, }); + app.builds.find({}, { _id: true }).then((builds) => { + builds.forEach((build) => app.buildActionStates.add(build._id!)); + }); + app.deployments.find({}, { _id: true }).then((deployments) => { + deployments.forEach((deployment) => + app.deployActionStates.add(deployment._id!) + ); + }); + app.servers.find({}, { _id: true }).then((servers) => { + servers.forEach((server) => app.serverActionStates.add(server._id!)); + }); + done(); });