feat(#159): suppressions métier dossiers/parents/enfants/AM/staff.
SuppressionService + DELETE /dossiers/:numero, cascades DELETE /users et DELETE /enfants?deleteDossier, flag sans_enfant, specs front #160. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
import { ForbiddenException, NotFoundException } from '@nestjs/common';
|
||||
import { SuppressionService } from './suppression.service';
|
||||
import { RoleType } from 'src/entities/users.entity';
|
||||
|
||||
describe('SuppressionService (#159)', () => {
|
||||
const dataSource = {
|
||||
transaction: jest.fn(async (cb: (m: unknown) => Promise<unknown>) =>
|
||||
cb({
|
||||
delete: jest.fn(),
|
||||
query: jest.fn(),
|
||||
}),
|
||||
),
|
||||
};
|
||||
|
||||
const usersRepository = {
|
||||
findOne: jest.fn(),
|
||||
delete: jest.fn(),
|
||||
count: jest.fn(),
|
||||
};
|
||||
const parentsRepository = {
|
||||
findOne: jest.fn(),
|
||||
find: jest.fn(),
|
||||
query: jest.fn(),
|
||||
};
|
||||
const amRepository = {
|
||||
findOne: jest.fn(),
|
||||
};
|
||||
const childrenRepository = {
|
||||
findOne: jest.fn(),
|
||||
delete: jest.fn(),
|
||||
save: jest.fn(),
|
||||
};
|
||||
const parentsChildrenRepository = {
|
||||
find: jest.fn(),
|
||||
};
|
||||
const amChildrenRepository = {
|
||||
find: jest.fn(),
|
||||
save: jest.fn(),
|
||||
count: jest.fn(),
|
||||
};
|
||||
|
||||
let service: SuppressionService;
|
||||
|
||||
const staff = {
|
||||
id: 'staff-1',
|
||||
role: RoleType.GESTIONNAIRE,
|
||||
} as never;
|
||||
|
||||
const admin = {
|
||||
id: 'admin-1',
|
||||
role: RoleType.ADMINISTRATEUR,
|
||||
} as never;
|
||||
|
||||
const superAdmin = {
|
||||
id: 'sa-1',
|
||||
role: RoleType.SUPER_ADMIN,
|
||||
} as never;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
service = new SuppressionService(
|
||||
dataSource as never,
|
||||
usersRepository as never,
|
||||
parentsRepository as never,
|
||||
amRepository as never,
|
||||
childrenRepository as never,
|
||||
parentsChildrenRepository as never,
|
||||
amChildrenRepository as never,
|
||||
);
|
||||
});
|
||||
|
||||
it('refuse self-delete', async () => {
|
||||
usersRepository.findOne.mockResolvedValue({
|
||||
id: 'admin-1',
|
||||
role: RoleType.ADMINISTRATEUR,
|
||||
});
|
||||
await expect(service.deleteUser('admin-1', admin)).rejects.toBeInstanceOf(
|
||||
ForbiddenException,
|
||||
);
|
||||
});
|
||||
|
||||
it('refuse gestionnaire deleting another gestionnaire', async () => {
|
||||
usersRepository.findOne.mockResolvedValue({
|
||||
id: 'g2',
|
||||
role: RoleType.GESTIONNAIRE,
|
||||
});
|
||||
await expect(service.deleteUser('g2', staff)).rejects.toBeInstanceOf(
|
||||
ForbiddenException,
|
||||
);
|
||||
});
|
||||
|
||||
it('dernier admin : refus si pas super_admin', async () => {
|
||||
usersRepository.findOne.mockResolvedValue({
|
||||
id: 'admin-2',
|
||||
role: RoleType.ADMINISTRATEUR,
|
||||
});
|
||||
usersRepository.count.mockResolvedValue(1);
|
||||
await expect(service.deleteUser('admin-2', admin)).rejects.toBeInstanceOf(
|
||||
ForbiddenException,
|
||||
);
|
||||
});
|
||||
|
||||
it('dernier admin : OK pour super_admin', async () => {
|
||||
usersRepository.findOne.mockResolvedValue({
|
||||
id: 'admin-2',
|
||||
role: RoleType.ADMINISTRATEUR,
|
||||
});
|
||||
usersRepository.count.mockResolvedValue(1);
|
||||
usersRepository.delete.mockResolvedValue({ affected: 1 });
|
||||
const res = await service.deleteUser('admin-2', superAdmin);
|
||||
expect(res.deleted_user_ids).toEqual(['admin-2']);
|
||||
});
|
||||
|
||||
it('delete AM : clos placements, pas d’enfants deleted', async () => {
|
||||
usersRepository.findOne.mockResolvedValue({
|
||||
id: 'am-1',
|
||||
role: RoleType.ASSISTANTE_MATERNELLE,
|
||||
});
|
||||
amRepository.findOne.mockResolvedValue({
|
||||
user_id: 'am-1',
|
||||
numero_dossier: '2026-000015',
|
||||
});
|
||||
amChildrenRepository.find.mockResolvedValue([
|
||||
{
|
||||
amId: 'am-1',
|
||||
enfantId: 'e1',
|
||||
child: { id: 'e1', status: 'garde' },
|
||||
},
|
||||
]);
|
||||
amChildrenRepository.count.mockResolvedValue(0);
|
||||
amChildrenRepository.save.mockImplementation(async (x) => x);
|
||||
childrenRepository.save.mockResolvedValue({});
|
||||
usersRepository.delete.mockResolvedValue({ affected: 1 });
|
||||
|
||||
const res = await service.deleteUser('am-1', staff);
|
||||
expect(res.deleted_enfant_ids).toEqual([]);
|
||||
expect(res.deleted_user_ids).toEqual(['am-1']);
|
||||
expect(res.type).toBe('assistante_maternelle');
|
||||
});
|
||||
|
||||
it('delete dossier famille introuvable', async () => {
|
||||
parentsRepository.findOne.mockResolvedValue(null);
|
||||
amRepository.findOne.mockResolvedValue(null);
|
||||
await expect(
|
||||
service.deleteDossier('2026-999999', staff),
|
||||
).rejects.toBeInstanceOf(NotFoundException);
|
||||
});
|
||||
|
||||
it('co-parent : delete user seul', async () => {
|
||||
usersRepository.findOne.mockResolvedValue({
|
||||
id: 'p2',
|
||||
role: RoleType.PARENT,
|
||||
});
|
||||
parentsRepository.findOne.mockResolvedValue({
|
||||
user_id: 'p2',
|
||||
numero_dossier: '2026-000010',
|
||||
co_parent: { id: 'p1' },
|
||||
});
|
||||
parentsRepository.query.mockResolvedValue([
|
||||
{ id: 'p1' },
|
||||
{ id: 'p2' },
|
||||
]);
|
||||
dataSource.transaction.mockImplementation(async (cb) =>
|
||||
cb({
|
||||
delete: jest.fn(),
|
||||
query: jest.fn(),
|
||||
}),
|
||||
);
|
||||
|
||||
const res = await service.deleteUser('p2', staff);
|
||||
expect(res.deleted_enfant_ids).toEqual([]);
|
||||
expect(res.deleted_user_ids).toEqual(['p2']);
|
||||
expect(res.message).toMatch(/co-parent/i);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,420 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
ForbiddenException,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { DataSource, In, IsNull, Repository } from 'typeorm';
|
||||
import { RoleType, Users } from 'src/entities/users.entity';
|
||||
import { Parents } from 'src/entities/parents.entity';
|
||||
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
||||
import { Children, StatutEnfantType } from 'src/entities/children.entity';
|
||||
import { ParentsChildren } from 'src/entities/parents_children.entity';
|
||||
import { AmChildren } from 'src/entities/am_children.entity';
|
||||
|
||||
export type SuppressionResult = {
|
||||
type?: 'famille' | 'assistante_maternelle';
|
||||
numero_dossier?: string;
|
||||
deleted_user_ids: string[];
|
||||
deleted_enfant_ids: string[];
|
||||
dossier_supprime?: boolean;
|
||||
message: string;
|
||||
};
|
||||
|
||||
const STAFF_METIER: RoleType[] = [
|
||||
RoleType.GESTIONNAIRE,
|
||||
RoleType.ADMINISTRATEUR,
|
||||
RoleType.SUPER_ADMIN,
|
||||
];
|
||||
|
||||
/**
|
||||
* Cascades de suppression métier — tickets #154 / #159.
|
||||
*/
|
||||
@Injectable()
|
||||
export class SuppressionService {
|
||||
constructor(
|
||||
private readonly dataSource: DataSource,
|
||||
@InjectRepository(Users)
|
||||
private readonly usersRepository: Repository<Users>,
|
||||
@InjectRepository(Parents)
|
||||
private readonly parentsRepository: Repository<Parents>,
|
||||
@InjectRepository(AssistanteMaternelle)
|
||||
private readonly amRepository: Repository<AssistanteMaternelle>,
|
||||
@InjectRepository(Children)
|
||||
private readonly childrenRepository: Repository<Children>,
|
||||
@InjectRepository(ParentsChildren)
|
||||
private readonly parentsChildrenRepository: Repository<ParentsChildren>,
|
||||
@InjectRepository(AmChildren)
|
||||
private readonly amChildrenRepository: Repository<AmChildren>,
|
||||
) {}
|
||||
|
||||
assertStaffMetier(currentUser: Users): void {
|
||||
if (!STAFF_METIER.includes(currentUser.role)) {
|
||||
throw new ForbiddenException('Accès refusé');
|
||||
}
|
||||
}
|
||||
|
||||
async deleteDossier(
|
||||
numeroDossier: string,
|
||||
currentUser: Users,
|
||||
): Promise<SuppressionResult> {
|
||||
this.assertStaffMetier(currentUser);
|
||||
const num = numeroDossier?.trim();
|
||||
if (!num) {
|
||||
throw new BadRequestException('Numéro de dossier requis.');
|
||||
}
|
||||
|
||||
const parentHit = await this.parentsRepository.findOne({
|
||||
where: { numero_dossier: num },
|
||||
});
|
||||
if (parentHit) {
|
||||
return this.deleteFamilleByNumero(num);
|
||||
}
|
||||
|
||||
const amHit = await this.amRepository.findOne({
|
||||
where: { numero_dossier: num },
|
||||
relations: ['user'],
|
||||
});
|
||||
if (amHit?.user) {
|
||||
return this.deleteAmUser(amHit.user.id);
|
||||
}
|
||||
|
||||
throw new NotFoundException('Aucun dossier trouvé pour ce numéro.');
|
||||
}
|
||||
|
||||
async deleteUser(
|
||||
id: string,
|
||||
currentUser: Users,
|
||||
): Promise<SuppressionResult> {
|
||||
const target = await this.usersRepository.findOne({ where: { id } });
|
||||
if (!target) {
|
||||
throw new NotFoundException('Utilisateur introuvable');
|
||||
}
|
||||
|
||||
if (target.id === currentUser.id) {
|
||||
throw new ForbiddenException('Vous ne pouvez pas supprimer votre propre compte.');
|
||||
}
|
||||
if (target.role === RoleType.SUPER_ADMIN) {
|
||||
throw new ForbiddenException('Le super administrateur ne peut pas être supprimé.');
|
||||
}
|
||||
|
||||
if (target.role === RoleType.PARENT) {
|
||||
this.assertStaffMetier(currentUser);
|
||||
return this.deleteParentUser(target.id);
|
||||
}
|
||||
if (target.role === RoleType.ASSISTANTE_MATERNELLE) {
|
||||
this.assertStaffMetier(currentUser);
|
||||
return this.deleteAmUser(target.id);
|
||||
}
|
||||
if (target.role === RoleType.GESTIONNAIRE) {
|
||||
if (
|
||||
currentUser.role !== RoleType.ADMINISTRATEUR &&
|
||||
currentUser.role !== RoleType.SUPER_ADMIN
|
||||
) {
|
||||
throw new ForbiddenException(
|
||||
'Seul un administrateur peut supprimer un gestionnaire.',
|
||||
);
|
||||
}
|
||||
await this.usersRepository.delete(target.id);
|
||||
return {
|
||||
deleted_user_ids: [target.id],
|
||||
deleted_enfant_ids: [],
|
||||
message: 'Gestionnaire supprimé.',
|
||||
};
|
||||
}
|
||||
if (target.role === RoleType.ADMINISTRATEUR) {
|
||||
await this.assertCanDeleteAdministrateur(target, currentUser);
|
||||
await this.usersRepository.delete(target.id);
|
||||
return {
|
||||
deleted_user_ids: [target.id],
|
||||
deleted_enfant_ids: [],
|
||||
message: 'Administrateur supprimé.',
|
||||
};
|
||||
}
|
||||
|
||||
throw new BadRequestException('Type d’utilisateur non supprimable via cet endpoint.');
|
||||
}
|
||||
|
||||
async deleteEnfant(
|
||||
enfantId: string,
|
||||
deleteDossier: boolean,
|
||||
currentUser: Users,
|
||||
): Promise<SuppressionResult> {
|
||||
this.assertStaffMetier(currentUser);
|
||||
|
||||
const child = await this.childrenRepository.findOne({
|
||||
where: { id: enfantId },
|
||||
relations: ['parentLinks', 'parentLinks.parent'],
|
||||
});
|
||||
if (!child) {
|
||||
throw new NotFoundException('Enfant introuvable');
|
||||
}
|
||||
|
||||
const parentIds = (child.parentLinks ?? [])
|
||||
.map((l) => l.parentId ?? l.parent?.user_id)
|
||||
.filter(Boolean) as string[];
|
||||
|
||||
let numero: string | undefined;
|
||||
if (parentIds.length > 0) {
|
||||
const parents = await this.parentsRepository.find({
|
||||
where: { user_id: In(parentIds) },
|
||||
});
|
||||
numero = parents.map((p) => p.numero_dossier?.trim()).find((n) => !!n);
|
||||
}
|
||||
|
||||
if (!numero) {
|
||||
await this.closePlacementsForEnfants([enfantId]);
|
||||
await this.childrenRepository.delete(enfantId);
|
||||
return {
|
||||
deleted_user_ids: [],
|
||||
deleted_enfant_ids: [enfantId],
|
||||
dossier_supprime: false,
|
||||
message: 'Enfant supprimé.',
|
||||
};
|
||||
}
|
||||
|
||||
const siblingIds = await this.listEnfantIdsForNumero(numero);
|
||||
const isLast = siblingIds.length <= 1;
|
||||
|
||||
if (isLast && deleteDossier) {
|
||||
const result = await this.deleteFamilleByNumero(numero);
|
||||
return {
|
||||
...result,
|
||||
dossier_supprime: true,
|
||||
message: 'Dernier enfant et dossier famille supprimés.',
|
||||
};
|
||||
}
|
||||
|
||||
await this.closePlacementsForEnfants([enfantId]);
|
||||
await this.childrenRepository.delete(enfantId);
|
||||
return {
|
||||
deleted_user_ids: [],
|
||||
deleted_enfant_ids: [enfantId],
|
||||
dossier_supprime: false,
|
||||
numero_dossier: numero,
|
||||
type: 'famille',
|
||||
message: isLast
|
||||
? 'Dernier enfant supprimé. Le dossier famille reste sans enfant.'
|
||||
: 'Enfant supprimé du dossier famille.',
|
||||
};
|
||||
}
|
||||
|
||||
/** Compte enfants liés à un numero_dossier famille (pour flag sans_enfant). */
|
||||
async countEnfantsForNumero(numeroDossier: string): Promise<number> {
|
||||
const ids = await this.listEnfantIdsForNumero(numeroDossier);
|
||||
return ids.length;
|
||||
}
|
||||
|
||||
private async assertCanDeleteAdministrateur(
|
||||
target: Users,
|
||||
currentUser: Users,
|
||||
): Promise<void> {
|
||||
if (
|
||||
currentUser.role !== RoleType.ADMINISTRATEUR &&
|
||||
currentUser.role !== RoleType.SUPER_ADMIN
|
||||
) {
|
||||
throw new ForbiddenException(
|
||||
'Seul un administrateur peut supprimer un administrateur.',
|
||||
);
|
||||
}
|
||||
const adminCount = await this.usersRepository.count({
|
||||
where: { role: RoleType.ADMINISTRATEUR },
|
||||
});
|
||||
if (adminCount <= 1) {
|
||||
if (currentUser.role !== RoleType.SUPER_ADMIN) {
|
||||
throw new ForbiddenException(
|
||||
'Seul le super administrateur peut supprimer le dernier administrateur.',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async deleteParentUser(userId: string): Promise<SuppressionResult> {
|
||||
const parent = await this.parentsRepository.findOne({
|
||||
where: { user_id: userId },
|
||||
relations: ['co_parent'],
|
||||
});
|
||||
if (!parent) {
|
||||
// Compte parent sans fiche — hard delete user
|
||||
await this.usersRepository.delete(userId);
|
||||
return {
|
||||
deleted_user_ids: [userId],
|
||||
deleted_enfant_ids: [],
|
||||
message: 'Parent supprimé.',
|
||||
};
|
||||
}
|
||||
|
||||
const numero = parent.numero_dossier?.trim();
|
||||
const foyerIds = numero
|
||||
? await this.listParentUserIdsForNumero(numero)
|
||||
: [userId];
|
||||
|
||||
const isLast = foyerIds.filter((id) => id !== userId).length === 0;
|
||||
|
||||
if (!isLast) {
|
||||
// Co-parent : retirer liens enfants de ce parent, clear co_parent refs, delete user
|
||||
await this.dataSource.transaction(async (manager) => {
|
||||
await manager.delete(ParentsChildren, { parentId: userId });
|
||||
await manager.query(
|
||||
`UPDATE parents SET id_co_parent = NULL WHERE id_co_parent = $1 OR id_utilisateur = $1`,
|
||||
[userId],
|
||||
);
|
||||
await manager.delete(Users, { id: userId });
|
||||
});
|
||||
return {
|
||||
deleted_user_ids: [userId],
|
||||
deleted_enfant_ids: [],
|
||||
numero_dossier: numero,
|
||||
type: 'famille',
|
||||
message: 'Parent retiré du dossier (co-parent).',
|
||||
};
|
||||
}
|
||||
|
||||
// Dernier parent : + enfants
|
||||
const enfantIds = numero
|
||||
? await this.listEnfantIdsForNumero(numero)
|
||||
: await this.listEnfantIdsForParent(userId);
|
||||
await this.closePlacementsForEnfants(enfantIds);
|
||||
await this.dataSource.transaction(async (manager) => {
|
||||
if (enfantIds.length) {
|
||||
await manager.delete(Children, { id: In(enfantIds) });
|
||||
}
|
||||
await manager.query(
|
||||
`UPDATE parents SET id_co_parent = NULL WHERE id_utilisateur = $1 OR id_co_parent = $1`,
|
||||
[userId],
|
||||
);
|
||||
await manager.delete(Users, { id: userId });
|
||||
});
|
||||
return {
|
||||
deleted_user_ids: [userId],
|
||||
deleted_enfant_ids: enfantIds,
|
||||
numero_dossier: numero,
|
||||
type: 'famille',
|
||||
message: 'Dernier parent et enfants rattachés supprimés.',
|
||||
};
|
||||
}
|
||||
|
||||
private async deleteFamilleByNumero(numero: string): Promise<SuppressionResult> {
|
||||
const parentIds = await this.listParentUserIdsForNumero(numero);
|
||||
if (parentIds.length === 0) {
|
||||
throw new NotFoundException('Aucun parent pour ce dossier.');
|
||||
}
|
||||
const enfantIds = await this.listEnfantIdsForNumero(numero);
|
||||
await this.closePlacementsForEnfants(enfantIds);
|
||||
|
||||
await this.dataSource.transaction(async (manager) => {
|
||||
if (enfantIds.length) {
|
||||
await manager.delete(Children, { id: In(enfantIds) });
|
||||
}
|
||||
await manager.query(
|
||||
`UPDATE parents SET id_co_parent = NULL WHERE id_utilisateur = ANY($1::uuid[]) OR id_co_parent = ANY($1::uuid[])`,
|
||||
[parentIds],
|
||||
);
|
||||
await manager.delete(Users, { id: In(parentIds) });
|
||||
});
|
||||
|
||||
return {
|
||||
type: 'famille',
|
||||
numero_dossier: numero,
|
||||
deleted_user_ids: parentIds,
|
||||
deleted_enfant_ids: enfantIds,
|
||||
message: 'Dossier famille supprimé.',
|
||||
};
|
||||
}
|
||||
|
||||
private async deleteAmUser(userId: string): Promise<SuppressionResult> {
|
||||
const am = await this.amRepository.findOne({ where: { user_id: userId } });
|
||||
const numero = am?.numero_dossier?.trim();
|
||||
|
||||
const active = await this.amChildrenRepository.find({
|
||||
where: { amId: userId, date_fin: IsNull() },
|
||||
relations: ['child'],
|
||||
});
|
||||
const now = new Date();
|
||||
for (const link of active) {
|
||||
link.date_fin = now;
|
||||
await this.amChildrenRepository.save(link);
|
||||
if (link.child) {
|
||||
await this.applySansGarde(link.child);
|
||||
}
|
||||
}
|
||||
|
||||
await this.usersRepository.delete(userId);
|
||||
return {
|
||||
type: 'assistante_maternelle',
|
||||
numero_dossier: numero,
|
||||
deleted_user_ids: [userId],
|
||||
deleted_enfant_ids: [],
|
||||
message: 'Dossier assistante maternelle supprimé.',
|
||||
};
|
||||
}
|
||||
|
||||
private async applySansGarde(child: Children): Promise<void> {
|
||||
if (
|
||||
child.status === StatutEnfantType.A_NAITRE ||
|
||||
child.status === StatutEnfantType.SCOLARISE
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const remaining = await this.amChildrenRepository.count({
|
||||
where: { enfantId: child.id, date_fin: IsNull() },
|
||||
});
|
||||
if (remaining === 0) {
|
||||
child.status = StatutEnfantType.SANS_GARDE;
|
||||
await this.childrenRepository.save(child);
|
||||
}
|
||||
}
|
||||
|
||||
private async closePlacementsForEnfants(enfantIds: string[]): Promise<void> {
|
||||
if (!enfantIds.length) return;
|
||||
const links = await this.amChildrenRepository.find({
|
||||
where: { enfantId: In(enfantIds), date_fin: IsNull() },
|
||||
relations: ['child'],
|
||||
});
|
||||
const now = new Date();
|
||||
for (const link of links) {
|
||||
link.date_fin = now;
|
||||
await this.amChildrenRepository.save(link);
|
||||
if (link.child) {
|
||||
await this.applySansGarde(link.child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async listParentUserIdsForNumero(numero: string): Promise<string[]> {
|
||||
const rows: Array<{ id: string }> = await this.parentsRepository.query(
|
||||
`
|
||||
SELECT DISTINCT x.id::text AS id FROM (
|
||||
SELECT id_utilisateur AS id FROM parents WHERE TRIM(numero_dossier) = $1
|
||||
UNION
|
||||
SELECT id_co_parent AS id FROM parents
|
||||
WHERE TRIM(numero_dossier) = $1 AND id_co_parent IS NOT NULL
|
||||
UNION
|
||||
SELECT p2.id_utilisateur AS id FROM parents p1
|
||||
JOIN parents p2 ON p2.id_utilisateur = p1.id_co_parent
|
||||
WHERE TRIM(p1.numero_dossier) = $1
|
||||
) x WHERE x.id IS NOT NULL
|
||||
`,
|
||||
[numero],
|
||||
);
|
||||
return rows.map((r) => r.id);
|
||||
}
|
||||
|
||||
private async listEnfantIdsForNumero(numero: string): Promise<string[]> {
|
||||
const parentIds = await this.listParentUserIdsForNumero(numero);
|
||||
if (!parentIds.length) return [];
|
||||
return this.listEnfantIdsForParents(parentIds);
|
||||
}
|
||||
|
||||
private async listEnfantIdsForParent(parentId: string): Promise<string[]> {
|
||||
return this.listEnfantIdsForParents([parentId]);
|
||||
}
|
||||
|
||||
private async listEnfantIdsForParents(parentIds: string[]): Promise<string[]> {
|
||||
const links = await this.parentsChildrenRepository.find({
|
||||
where: { parentId: In(parentIds) },
|
||||
});
|
||||
return [...new Set(links.map((l) => l.enfantId))];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Users } from 'src/entities/users.entity';
|
||||
import { Parents } from 'src/entities/parents.entity';
|
||||
import { AssistanteMaternelle } from 'src/entities/assistantes_maternelles.entity';
|
||||
import { Children } from 'src/entities/children.entity';
|
||||
import { ParentsChildren } from 'src/entities/parents_children.entity';
|
||||
import { AmChildren } from 'src/entities/am_children.entity';
|
||||
import { SuppressionService } from './suppression.service';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([
|
||||
Users,
|
||||
Parents,
|
||||
AssistanteMaternelle,
|
||||
Children,
|
||||
ParentsChildren,
|
||||
AmChildren,
|
||||
]),
|
||||
],
|
||||
providers: [SuppressionService],
|
||||
exports: [SuppressionService],
|
||||
})
|
||||
export class SuppressionsModule {}
|
||||
Reference in New Issue
Block a user