-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
user mgmt supervisor backend implementation
- Loading branch information
1 parent
2e08cb6
commit b255a96
Showing
23 changed files
with
636 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
app/src/db/migrations/20240717000000_007_access-request.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import stamps from '../stamps'; | ||
|
||
import type { Knex } from 'knex'; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
return ( | ||
Promise.resolve() | ||
// Create the access_request table | ||
.then(() => | ||
knex.schema.createTable('access_request', (table) => { | ||
table.uuid('access_request_id').primary(); | ||
table.uuid('user_id').notNullable().references('user_id').inTable('user'); | ||
table.text('role'); | ||
table | ||
.enu('status', ['Approved', 'Pending', 'Rejected'], { | ||
useNative: true, | ||
enumName: 'access_request_status_enum' | ||
}) | ||
.defaultTo('Pending') | ||
.notNullable(); | ||
table.boolean('grant').notNullable(); | ||
stamps(knex, table); | ||
}) | ||
) | ||
|
||
.then(() => | ||
knex.schema.raw(`create trigger before_update_access_request_trigger | ||
before update on public.access_request | ||
for each row execute procedure public.set_updated_at();`) | ||
) | ||
|
||
.then(() => | ||
knex.schema.raw(`CREATE TRIGGER audit_access_request_trigger | ||
AFTER UPDATE OR DELETE ON access_request | ||
FOR EACH ROW EXECUTE PROCEDURE audit.if_modified_func();`) | ||
) | ||
); | ||
} | ||
|
||
export async function down(knex: Knex): Promise<void> { | ||
return ( | ||
Promise.resolve() | ||
// Drop triggers | ||
.then(() => knex.schema.raw('DROP TRIGGER IF EXISTS before_update_access_request_trigger ON access_request')) | ||
.then(() => knex.schema.raw('DROP TRIGGER IF EXISTS audit_access_request_trigger ON access_request')) | ||
// Drop the access_request table | ||
.then(() => knex.schema.dropTableIfExists('access_request')) | ||
// Drop the access_request_status_enum type | ||
.then(() => knex.schema.raw('DROP TYPE IF EXISTS access_request_status_enum')) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Prisma } from '@prisma/client'; | ||
|
||
import type { Stamps } from '../stamps'; | ||
import type { AccessRequest } from '../../types/AccessRequest'; // Import the access_request_status_enum type | ||
import { UserStatus } from '../../utils/enums/application'; | ||
|
||
// Define types | ||
const _accessRequest = Prisma.validator<Prisma.access_requestDefaultArgs>()({}); | ||
|
||
type PrismaRelationAccessRequest = Omit<Prisma.access_requestGetPayload<typeof _accessRequest>, keyof Stamps>; | ||
|
||
export default { | ||
toPrismaModel(input: AccessRequest): PrismaRelationAccessRequest { | ||
return { | ||
access_request_id: input.accessRequestId, | ||
grant: input.grant, | ||
role: input.role, | ||
status: input.status as UserStatus, // Cast the status property to UserStatus enum | ||
user_id: input.userId | ||
}; | ||
}, | ||
|
||
fromPrismaModel(input: PrismaRelationAccessRequest): AccessRequest { | ||
return { | ||
accessRequestId: input.access_request_id, | ||
grant: input.grant, | ||
role: input.role, | ||
userId: input.user_id as string, | ||
status: input.status as UserStatus // Cast the status property to UserStatus enum | ||
}; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { IStamps } from '../interfaces/IStamps'; | ||
import { UserStatus } from '../utils/enums/application'; | ||
|
||
export type AccessRequest = { | ||
accessRequestId: string; // Primary key | ||
grant: boolean; | ||
role: string | null; | ||
status: UserStatus; | ||
userId: string; | ||
} & Partial<IStamps>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.