Skip to content

Commit

Permalink
fix: filter out null hotels - fix #253 (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
pagoru authored Jan 22, 2025
1 parent 50ac2a2 commit da1a300
Showing 1 changed file with 52 additions and 51 deletions.
103 changes: 52 additions & 51 deletions app/server/src/modules/api/v3/hotel/list.request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,60 +14,61 @@ export const listRequest: RequestType = {
func: async () => {
const $hotels = await System.hotels.getList();

const hotels = await Promise.all(
$hotels
.filter((hotel) => hotel.public)
.map(async (hotel) => {
const owner = await System.accounts.get(hotel.accountId);
const client = hotel.integrations.find(
(integration) => integration.type === "client",
);
const web = hotel.integrations.find(
(integration) => integration.type === "web",
);
const hotels = (
await Promise.all(
$hotels
.filter((hotel) => hotel.public)
.map(async (hotel) => {
const owner = await System.accounts.get(hotel.accountId);
const client = hotel.integrations.find(
(integration) => integration.type === "client",
);
const web = hotel.integrations.find(
(integration) => integration.type === "web",
);

const clientAccounts = client
? (
await System.hotels.getAccountsByIntegrationId(
hotel.hotelId,
client.integrationId,
)
).length
: 0;
const webAccounts = web
? (
await System.hotels.getAccountsByIntegrationId(
hotel.hotelId,
web.integrationId,
)
).length
: 0;
const clientAccounts = client
? (
await System.hotels.getAccountsByIntegrationId(
hotel.hotelId,
client.integrationId,
)
).length
: 0;
const webAccounts = web
? (
await System.hotels.getAccountsByIntegrationId(
hotel.hotelId,
web.integrationId,
)
).length
: 0;

//if hotel is a ghost town, filter it out
if ((!client && !web) || clientAccounts + webAccounts === 0)
return null;
//if hotel is a ghost town, filter it out
if ((!client && !web) || clientAccounts + webAccounts === 0)
return null;

return {
name: hotel.name,
owner: owner.username,
client: client
? {
name: client.name,
url: client.redirectUrl,
accounts: clientAccounts,
}
: null,
web: web
? {
name: web.name,
url: web.redirectUrl,
accounts: webAccounts,
}
: null,
};
})
.filter(Boolean),
);
return {
name: hotel.name,
owner: owner.username,
client: client
? {
name: client.name,
url: client.redirectUrl,
accounts: clientAccounts,
}
: null,
web: web
? {
name: web.name,
url: web.redirectUrl,
accounts: webAccounts,
}
: null,
};
}),
)
).filter(Boolean);
return getResponse(HttpStatusCode.OK, {
data: {
hotels,
Expand Down

0 comments on commit da1a300

Please sign in to comment.