feat(#194): schéma cartes SYSTEM (types, instances, audience, responses).
Migration + seeds absence/congé/arrêt + entités TypeORM. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { CardInstance } from './card_instances.entity';
|
||||
import { Users } from './users.entity';
|
||||
|
||||
@Entity('card_audience_members', { schema: 'public' })
|
||||
export class CardAudienceMember {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ name: 'id_card', type: 'uuid' })
|
||||
id_card: string;
|
||||
|
||||
@ManyToOne(() => CardInstance, (c) => c.audience, { onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'id_card', referencedColumnName: 'id' })
|
||||
card: CardInstance;
|
||||
|
||||
@Column({ name: 'id_utilisateur', type: 'uuid' })
|
||||
id_utilisateur: string;
|
||||
|
||||
@ManyToOne(() => Users, { onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'id_utilisateur', referencedColumnName: 'id' })
|
||||
user: Users;
|
||||
|
||||
@Column({ name: 'role_snapshot', type: 'varchar', length: 64 })
|
||||
role_snapshot: string;
|
||||
|
||||
@Column({ name: 'is_creator', type: 'boolean', default: false })
|
||||
is_creator: boolean;
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
import { AmChildren } from './am_children.entity';
|
||||
import { AbsencesGarde } from './absences_garde.entity';
|
||||
import { Users } from './users.entity';
|
||||
import { CardType } from './card_types.entity';
|
||||
import { CardAudienceMember } from './card_audience_members.entity';
|
||||
import { CardResponse } from './card_responses.entity';
|
||||
|
||||
export enum CardInstanceStatutType {
|
||||
OUVERTE = 'ouverte',
|
||||
REFUSEE = 'refusee',
|
||||
TRAITEE = 'traitee',
|
||||
}
|
||||
|
||||
export enum CardOperationType {
|
||||
CREATE = 'create',
|
||||
UPDATE = 'update',
|
||||
}
|
||||
|
||||
@Entity('card_instances', { schema: 'public' })
|
||||
export class CardInstance {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ name: 'type_code', type: 'varchar', length: 64 })
|
||||
type_code: string;
|
||||
|
||||
@ManyToOne(() => CardType, { onDelete: 'RESTRICT' })
|
||||
@JoinColumn({ name: 'type_code', referencedColumnName: 'code' })
|
||||
type: CardType;
|
||||
|
||||
@Column({ name: 'id_placement', type: 'uuid' })
|
||||
id_placement: string;
|
||||
|
||||
@ManyToOne(() => AmChildren, { onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'id_placement', referencedColumnName: 'id' })
|
||||
placement: AmChildren;
|
||||
|
||||
@Column({ name: 'id_absence', type: 'uuid', nullable: true })
|
||||
id_absence?: string;
|
||||
|
||||
@ManyToOne(() => AbsencesGarde, { nullable: true, onDelete: 'SET NULL' })
|
||||
@JoinColumn({ name: 'id_absence', referencedColumnName: 'id' })
|
||||
absence?: AbsencesGarde;
|
||||
|
||||
@Column({ name: 'cree_par', type: 'uuid', nullable: true })
|
||||
cree_par?: string;
|
||||
|
||||
@ManyToOne(() => Users, { nullable: true, onDelete: 'SET NULL' })
|
||||
@JoinColumn({ name: 'cree_par', referencedColumnName: 'id' })
|
||||
createdBy?: Users;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: CardOperationType,
|
||||
enumName: 'card_operation_type',
|
||||
name: 'operation',
|
||||
default: CardOperationType.CREATE,
|
||||
})
|
||||
operation: CardOperationType;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: CardInstanceStatutType,
|
||||
enumName: 'card_instance_statut_type',
|
||||
name: 'statut',
|
||||
default: CardInstanceStatutType.OUVERTE,
|
||||
})
|
||||
statut: CardInstanceStatutType;
|
||||
|
||||
@Column({ name: 'payload', type: 'jsonb', default: {} })
|
||||
payload: Record<string, unknown>;
|
||||
|
||||
@Column({ name: 'purge_at', type: 'timestamptz' })
|
||||
purge_at: Date;
|
||||
|
||||
@OneToMany(() => CardAudienceMember, (m) => m.card)
|
||||
audience: CardAudienceMember[];
|
||||
|
||||
@OneToMany(() => CardResponse, (r) => r.card)
|
||||
responses: CardResponse[];
|
||||
|
||||
@CreateDateColumn({ name: 'cree_le', type: 'timestamptz' })
|
||||
cree_le: Date;
|
||||
|
||||
@UpdateDateColumn({ name: 'modifie_le', type: 'timestamptz' })
|
||||
modifie_le: Date;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
PrimaryGeneratedColumn,
|
||||
} from 'typeorm';
|
||||
import { CardInstance } from './card_instances.entity';
|
||||
import { Users } from './users.entity';
|
||||
|
||||
export enum CardResponseActionType {
|
||||
ACCEPT = 'accept',
|
||||
REFUSE = 'refuse',
|
||||
ACK = 'ack',
|
||||
}
|
||||
|
||||
@Entity('card_responses', { schema: 'public' })
|
||||
export class CardResponse {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Column({ name: 'id_card', type: 'uuid' })
|
||||
id_card: string;
|
||||
|
||||
@ManyToOne(() => CardInstance, (c) => c.responses, { onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'id_card', referencedColumnName: 'id' })
|
||||
card: CardInstance;
|
||||
|
||||
@Column({ name: 'id_utilisateur', type: 'uuid' })
|
||||
id_utilisateur: string;
|
||||
|
||||
@ManyToOne(() => Users, { onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'id_utilisateur', referencedColumnName: 'id' })
|
||||
user: Users;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: CardResponseActionType,
|
||||
enumName: 'card_response_action_type',
|
||||
name: 'action',
|
||||
})
|
||||
action: CardResponseActionType;
|
||||
|
||||
@Column({ name: 'comment', type: 'text', nullable: true })
|
||||
comment?: string;
|
||||
|
||||
@CreateDateColumn({ name: 'cree_le', type: 'timestamptz' })
|
||||
cree_le: Date;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
PrimaryColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
|
||||
export enum CardResponseModeType {
|
||||
NONE = 'none',
|
||||
ACK = 'ack',
|
||||
ACCEPT_REFUSE = 'accept_refuse',
|
||||
}
|
||||
|
||||
@Entity('card_types', { schema: 'public' })
|
||||
export class CardType {
|
||||
@PrimaryColumn({ name: 'code', type: 'varchar', length: 64 })
|
||||
code: string;
|
||||
|
||||
@Column({ name: 'system', type: 'boolean', default: true })
|
||||
system: boolean;
|
||||
|
||||
@Column({ name: 'titre', type: 'varchar', length: 120 })
|
||||
titre: string;
|
||||
|
||||
@Column({ name: 'emitter_roles', type: 'text', array: true })
|
||||
emitter_roles: string[];
|
||||
|
||||
@Column({ name: 'recipient_roles', type: 'text', array: true })
|
||||
recipient_roles: string[];
|
||||
|
||||
@Column({ name: 'audience_resolver', type: 'varchar', length: 64 })
|
||||
audience_resolver: string;
|
||||
|
||||
@Column({
|
||||
type: 'enum',
|
||||
enum: CardResponseModeType,
|
||||
enumName: 'card_response_mode_type',
|
||||
name: 'response_mode',
|
||||
})
|
||||
response_mode: CardResponseModeType;
|
||||
|
||||
@Column({ name: 'retention_days', type: 'int', default: 14 })
|
||||
retention_days: number;
|
||||
|
||||
@Column({ name: 'couleur', type: 'varchar', length: 32, nullable: true })
|
||||
couleur?: string;
|
||||
|
||||
@CreateDateColumn({ name: 'cree_le', type: 'timestamptz' })
|
||||
cree_le: Date;
|
||||
|
||||
@UpdateDateColumn({ name: 'modifie_le', type: 'timestamptz' })
|
||||
modifie_le: Date;
|
||||
}
|
||||
Reference in New Issue
Block a user