Skip to content
This repository has been archived by the owner on Nov 2, 2024. It is now read-only.

Commit

Permalink
Add back stab hidden mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Macludde committed Aug 21, 2023
1 parent 2d6ddf6 commit 82042fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions backend/services/core/src/datasources/Mandate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export default class MandateAPI extends dbUtils.KnexDataSource {
const res = (await this.knex<sql.Mandate>('mandates').select('*').where({ id }))[0];

if (!res) { return undefined; }
if (await this.isStabHidden() && STAB_IDS.includes(res.position_id)) {
return undefined;
}
return convertMandate(res);
});
}
Expand Down Expand Up @@ -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);
});
}
Expand Down
3 changes: 3 additions & 0 deletions backend/services/core/src/datasources/Position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => { });
}
Expand Down

0 comments on commit 82042fc

Please sign in to comment.