Skip to content

Commit

Permalink
add revert migration
Browse files Browse the repository at this point in the history
  • Loading branch information
c1495616js committed Sep 24, 2024
1 parent 7714762 commit 23df85d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
31 changes: 31 additions & 0 deletions apps/api/src/migration/1727200471805-AddBackReportRoleToHA.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddBackReportRoleToHA1727200471805 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
INSERT INTO employee_roles_role (employee_id, role_id)
SELECT e.id, r.id
FROM employee e
JOIN ien_ha_pcn ha ON ha.title = e.organization
JOIN role r ON r.slug = 'reporting'
WHERE NOT EXISTS (
SELECT 1
FROM employee_roles_role err
WHERE err.employee_id = e.id
AND err.role_id = r.id
);
`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`
DELETE FROM employee_roles_role err
USING employee e, role r, ien_ha_pcn ha
WHERE
e.id = err.employee_id AND
ha.title = e.organization AND
r.id = err.role_id AND
r.slug = 'reporting';
`);
}
}
5 changes: 1 addition & 4 deletions apps/web/src/components/user/UserRoles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ export const UserRoles = ({ user, updateUser }: UserRolesProps) => {
if (isAdmin(user)) {
return availableRoles;
}
return availableRoles.filter(
role =>
role.slug !== RoleSlug.BccnmNcas && (!user.ha_pcn_id || role.slug !== RoleSlug.Reporting),
);
return availableRoles.filter(role => role.slug !== RoleSlug.BccnmNcas);
};

const getRoleSelector = (role: Role) => {
Expand Down

0 comments on commit 23df85d

Please sign in to comment.