From 520ed8cb4d04004717e25185a8805e05ece413d7 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 25 Jan 2023 11:18:16 +0900 Subject: [PATCH] refactor(server): fix type errors --- packages/backend/src/core/AntennaService.ts | 10 ++++++-- packages/backend/src/core/RoleService.ts | 26 +++++++++++++-------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/backend/src/core/AntennaService.ts b/packages/backend/src/core/AntennaService.ts index be755f7dab..7db8c43ea5 100644 --- a/packages/backend/src/core/AntennaService.ts +++ b/packages/backend/src/core/AntennaService.ts @@ -77,10 +77,16 @@ export class AntennaService implements OnApplicationShutdown { const { type, body } = obj.message as StreamMessages['internal']['payload']; switch (type) { case 'antennaCreated': - this.antennas.push(body); + this.antennas.push({ + ...body, + createdAt: new Date(body.createdAt), + }); break; case 'antennaUpdated': - this.antennas[this.antennas.findIndex(a => a.id === body.id)] = body; + this.antennas[this.antennas.findIndex(a => a.id === body.id)] = { + ...body, + createdAt: new Date(body.createdAt), + }; break; case 'antennaDeleted': this.antennas = this.antennas.filter(a => a.id !== body.id); diff --git a/packages/backend/src/core/RoleService.ts b/packages/backend/src/core/RoleService.ts index c0f5eae3d7..f8f9231cdd 100644 --- a/packages/backend/src/core/RoleService.ts +++ b/packages/backend/src/core/RoleService.ts @@ -91,10 +91,12 @@ export class RoleService implements OnApplicationShutdown { case 'roleCreated': { const cached = this.rolesCache.get(null); if (cached) { - body.createdAt = new Date(body.createdAt); - body.updatedAt = new Date(body.updatedAt); - body.lastUsedAt = new Date(body.lastUsedAt); - cached.push(body); + cached.push({ + ...body, + createdAt: new Date(body.createdAt), + updatedAt: new Date(body.updatedAt), + lastUsedAt: new Date(body.lastUsedAt), + }); } break; } @@ -103,10 +105,12 @@ export class RoleService implements OnApplicationShutdown { if (cached) { const i = cached.findIndex(x => x.id === body.id); if (i > -1) { - body.createdAt = new Date(body.createdAt); - body.updatedAt = new Date(body.updatedAt); - body.lastUsedAt = new Date(body.lastUsedAt); - cached[i] = body; + cached[i] = { + ...body, + createdAt: new Date(body.createdAt), + updatedAt: new Date(body.updatedAt), + lastUsedAt: new Date(body.lastUsedAt), + }; } } break; @@ -121,8 +125,10 @@ export class RoleService implements OnApplicationShutdown { case 'userRoleAssigned': { const cached = this.roleAssignmentByUserIdCache.get(body.userId); if (cached) { - body.createdAt = new Date(body.createdAt); - cached.push(body); + cached.push({ + ...body, + createdAt: new Date(body.createdAt), + }); } break; }