From 82042fc26aef4957241119203047f55c3da3b85c Mon Sep 17 00:00:00 2001 From: Ludvig Date: Mon, 21 Aug 2023 15:07:27 +0200 Subject: [PATCH] Add back stab hidden mode --- backend/services/core/src/datasources/Mandate.ts | 11 +++++++++++ backend/services/core/src/datasources/Position.ts | 3 +++ 2 files changed, 14 insertions(+) diff --git a/backend/services/core/src/datasources/Mandate.ts b/backend/services/core/src/datasources/Mandate.ts index e68effd41..95d1751be 100644 --- a/backend/services/core/src/datasources/Mandate.ts +++ b/backend/services/core/src/datasources/Mandate.ts @@ -22,6 +22,9 @@ export default class MandateAPI extends dbUtils.KnexDataSource { const res = (await this.knex('mandates').select('*').where({ id }))[0]; if (!res) { return undefined; } + if (await this.isStabHidden() && STAB_IDS.includes(res.position_id)) { + return undefined; + } return convertMandate(res); }); } @@ -106,6 +109,14 @@ export default class MandateAPI extends dbUtils.KnexDataSource { query = query.andWhereRaw('CURRENT_DATE BETWEEN start_date AND end_date'); } const res = await query; + if (await this.isStabHidden()) { + // if user has an active stab mandate, hide all other mandates + if (res.some((m) => m.end_date > new Date() && STAB_IDS.includes(m.position_id))) { + return []; + } + // otherwise just filter out their old stab mandates + return res.filter((m) => !STAB_IDS.includes(m.position_id)).map(convertMandate); + } return res.map(convertMandate); }); } diff --git a/backend/services/core/src/datasources/Position.ts b/backend/services/core/src/datasources/Position.ts index 3b00d3ae0..26e98619a 100644 --- a/backend/services/core/src/datasources/Position.ts +++ b/backend/services/core/src/datasources/Position.ts @@ -17,6 +17,9 @@ export default class PositionAPI extends dbUtils.KnexDataSource { return undefined; } + if (await this.isStabHidden() && STAB_IDS.includes(position.id)) { + return undefined; + } if (!position.active) { await this.withAccess('core:position:inactive:read', ctx, async () => { }); }