Skip to content

Commit

Permalink
fix: removed invalid connection from null hotels - fix #263 (#264)
Browse files Browse the repository at this point in the history
* fix: accountId is undefined on connections - fix #263

* fix: removed invalid connection from null hotels - fix #263

* fix: removed invalid connection from null hotels - fix #263
  • Loading branch information
pagoru authored Jan 23, 2025
1 parent 087b82e commit c43b6cc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Migration, DbMutable } from "@oh/utils";

export default {
id: "2025-01-23--22-00-remove-invalid-connections",
description: `remove invalid 'connections' from null hotels`,
up: async (db: DbMutable) => {
const connections = await db.list({
prefix: ["integrationsByAccountId"],
});
for await (const connection of connections) {
const hotel = await db.get(["hotels", connection.value.hotelId]);
if (!hotel) await db.delete(connection.key);
}
},
down: async (db: DbMutable) => {},
} as Migration;
1 change: 1 addition & 0 deletions app/server/src/modules/migrations/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const MIGRATION_LIST = [
await import(
"./2025-01-23--15-15-remove-integrations-by-hotels-by-account-id.migration.ts"
),
await import("./2025-01-23--22-00-remove-invalid-connections.migration.ts"),
];

export const Migrations = (() => {
Expand Down
12 changes: 10 additions & 2 deletions app/server/src/modules/system/hotels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const hotels = () => {
) => {
return (
await System.db.list({
prefix: ["integrationsByHotelsByAccountId"],
prefix: ["integrationsByAccountId"],
})
).filter(({ key }) => key[2] === hotelId && key[3] === integrationId);
};
Expand Down Expand Up @@ -100,8 +100,16 @@ export const hotels = () => {
hotelsIdList.filter(($hotelId: string) => hotelId !== $hotelId),
);

for (const { integrationId } of hotel.integrations)
for (const { integrationId } of hotel.integrations) {
const accounts = await getAccountsByIntegrationId(hotelId, integrationId);

for (const {
value: { accountId },
} of accounts)
await System.connections.remove(accountId, hotelId, integrationId);

await System.db.delete(["hotelsByConnectId", integrationId]);
}

await System.db.delete(["hotels", hotelId]);
};
Expand Down

0 comments on commit c43b6cc

Please sign in to comment.