-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(general): add structure information management and messages for …
…users
- Loading branch information
Showing
68 changed files
with
3,398 additions
and
162 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
Binary file not shown.
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
34 changes: 34 additions & 0 deletions
34
packages/backend/src/_migrations/1723547616571-create-structure-information-migration.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,34 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
import { domifaConfig } from "../config"; | ||
|
||
export class CreateStructureInformationMigration1723547616571 | ||
implements MigrationInterface | ||
{ | ||
name = "CreateStructureInformationMigration1723547616571"; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
if ( | ||
domifaConfig().envId === "prod" || | ||
domifaConfig().envId === "preprod" || | ||
domifaConfig().envId === "local" | ||
) { | ||
await queryRunner.query( | ||
`CREATE TABLE "structure_information" ("uuid" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "version" integer NOT NULL, "title" character varying NOT NULL, "description" character varying, "isTemporary" boolean NOT NULL DEFAULT false, "startDate" TIMESTAMP, "endDate" TIMESTAMP, "type" character varying NOT NULL, "createdBy" jsonb, "structureId" integer NOT NULL, CONSTRAINT "PK_b51c75b37769abf1fdf28fc89ef" PRIMARY KEY ("uuid"))` | ||
); | ||
await queryRunner.query( | ||
`CREATE INDEX "IDX_17cd35c9fdcd9ab82015a46b22" ON "structure_information" ("structureId") ` | ||
); | ||
await queryRunner.query( | ||
`ALTER TABLE "structure_information" ADD CONSTRAINT "FK_17cd35c9fdcd9ab82015a46b22c" FOREIGN KEY ("structureId") REFERENCES "structure"("id") ON DELETE CASCADE ON UPDATE NO ACTION` | ||
); | ||
} | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`ALTER TABLE "structure_information" DROP CONSTRAINT "FK_17cd35c9fdcd9ab82015a46b22c"` | ||
); | ||
|
||
await queryRunner.query(`DROP TABLE "structure_information"`); | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
packages/backend/src/auth/decorators/current-structure-information.decorator.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,9 @@ | ||
import { createParamDecorator, ExecutionContext } from "@nestjs/common"; | ||
import { UserStructureAuthenticated } from "../../_common/model"; | ||
|
||
export const CurrentStructureInformation = createParamDecorator( | ||
(_data: unknown, ctx: ExecutionContext) => { | ||
const request = ctx.switchToHttp().getRequest(); | ||
return request.structureInformation as UserStructureAuthenticated; | ||
} | ||
); |
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
64 changes: 64 additions & 0 deletions
64
packages/backend/src/auth/guards/structure-information-access.guard.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,64 @@ | ||
import { | ||
CanActivate, | ||
ExecutionContext, | ||
HttpException, | ||
HttpStatus, | ||
Injectable, | ||
} from "@nestjs/common"; | ||
|
||
import { appLogger } from "../../util"; | ||
import { structureInformationRepository } from "../../database"; | ||
|
||
@Injectable() | ||
export class StructureInformationAccessGuard implements CanActivate { | ||
public async canActivate(context: ExecutionContext) { | ||
const r = context.switchToHttp().getRequest(); | ||
|
||
if ( | ||
typeof r.params.uuid === "undefined" || | ||
typeof r.user.structureId === "undefined" | ||
) { | ||
appLogger.error( | ||
`[StructureInformationAccessGuard] invalid uuid or structureId`, | ||
{ | ||
sentry: true, | ||
context: { | ||
usagerRef: r?.params?.uui, | ||
structureId: r?.user?.structureId, | ||
user: r?.user?._id, | ||
}, | ||
} | ||
); | ||
throw new HttpException( | ||
"STRUCTURE_INFORMATION_NOT_FOUND", | ||
HttpStatus.BAD_REQUEST | ||
); | ||
} | ||
|
||
const uuid = r.params.uuid; | ||
const structureId = parseInt(r.user.structureId, 10); | ||
|
||
try { | ||
const structureInformation = | ||
await structureInformationRepository.findOneOrFail({ | ||
where: { | ||
structureId, | ||
uuid, | ||
}, | ||
}); | ||
r.structureInformation = structureInformation; | ||
return r; | ||
} catch (e) { | ||
appLogger.error(`[UsagerAccessGuard] structureInformation not found`, { | ||
sentry: true, | ||
context: { | ||
uuid, | ||
structureId, | ||
user: r?.user?._id, | ||
role: r?.user?.role, | ||
}, | ||
}); | ||
throw new HttpException("USAGER_NOT_FOUND", HttpStatus.BAD_REQUEST); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/backend/src/database/entities/structure/StructureInformationTable.typeorm.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,43 @@ | ||
import { | ||
StructureInformation, | ||
StructureInformationType, | ||
UserStructureResume, | ||
} from "@domifa/common"; | ||
import { Entity, Column, Index, JoinColumn, ManyToOne } from "typeorm"; | ||
import { AppTypeormTable } from "../_core"; | ||
import { StructureTable } from "./StructureTable.typeorm"; | ||
|
||
@Entity({ name: "structure_information" }) | ||
export class StructureInformationTable | ||
extends AppTypeormTable<StructureInformationTable> | ||
implements StructureInformation | ||
{ | ||
@Column({ type: "varchar" }) | ||
title: string; | ||
|
||
@Column({ nullable: true }) | ||
description: string; | ||
|
||
@Column({ default: false }) | ||
isTemporary: boolean; | ||
|
||
@Column({ type: "timestamp", nullable: true }) | ||
startDate: Date | null; | ||
|
||
@Column({ type: "timestamp", nullable: true }) | ||
endDate: Date | null; | ||
|
||
@Column({ type: "varchar" }) | ||
type: StructureInformationType; | ||
|
||
@Column({ type: "jsonb", nullable: true }) | ||
createdBy: UserStructureResume; | ||
|
||
@Index() | ||
@ManyToOne(() => StructureTable, (structure) => structure.id, { | ||
onDelete: "CASCADE", | ||
}) | ||
@Column({ type: "integer", nullable: false }) | ||
@JoinColumn({ name: "structureId", referencedColumnName: "id" }) | ||
public structureId: number; | ||
} |
Oops, something went wrong.