feat: Modules de gestion des entités principales - Ajout des modules Machines, Composants et Pièces avec leurs services et contrôleurs
This commit is contained in:
21
src/composants/composants.controller.spec.ts
Normal file
21
src/composants/composants.controller.spec.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { ComposantsController } from './composants.controller';
|
||||
import { ComposantsService } from './composants.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
describe('ComposantsController', () => {
|
||||
let controller: ComposantsController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [ComposantsController],
|
||||
providers: [ComposantsService, PrismaService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<ComposantsController>(ComposantsController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
43
src/composants/composants.controller.ts
Normal file
43
src/composants/composants.controller.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { ComposantsService } from './composants.service';
|
||||
import { CreateComposantDto, UpdateComposantDto } from '../shared/dto/composant.dto';
|
||||
|
||||
@Controller('composants')
|
||||
export class ComposantsController {
|
||||
constructor(private readonly composantsService: ComposantsService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createComposantDto: CreateComposantDto) {
|
||||
return this.composantsService.create(createComposantDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.composantsService.findAll();
|
||||
}
|
||||
|
||||
@Get('hierarchy/:machineId')
|
||||
findHierarchy(@Param('machineId') machineId: string) {
|
||||
return this.composantsService.findHierarchy(machineId);
|
||||
}
|
||||
|
||||
@Get('machine/:machineId')
|
||||
findByMachine(@Param('machineId') machineId: string) {
|
||||
return this.composantsService.findByMachine(machineId);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.composantsService.findOne(id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateComposantDto: UpdateComposantDto) {
|
||||
return this.composantsService.update(id, updateComposantDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.composantsService.remove(id);
|
||||
}
|
||||
}
|
||||
9
src/composants/composants.module.ts
Normal file
9
src/composants/composants.module.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ComposantsController } from './composants.controller';
|
||||
import { ComposantsService } from './composants.service';
|
||||
|
||||
@Module({
|
||||
controllers: [ComposantsController],
|
||||
providers: [ComposantsService]
|
||||
})
|
||||
export class ComposantsModule {}
|
||||
19
src/composants/composants.service.spec.ts
Normal file
19
src/composants/composants.service.spec.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { ComposantsService } from './composants.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
describe('ComposantsService', () => {
|
||||
let service: ComposantsService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [ComposantsService, PrismaService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<ComposantsService>(ComposantsService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
267
src/composants/composants.service.ts
Normal file
267
src/composants/composants.service.ts
Normal file
@@ -0,0 +1,267 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { CreateComposantDto, UpdateComposantDto } from '../shared/dto/composant.dto';
|
||||
|
||||
@Injectable()
|
||||
export class ComposantsService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async create(createComposantDto: CreateComposantDto) {
|
||||
return this.prisma.composant.create({
|
||||
data: createComposantDto,
|
||||
include: {
|
||||
machine: true,
|
||||
parentComposant: true,
|
||||
typeComposant: true,
|
||||
sousComposants: {
|
||||
include: {
|
||||
typeComposant: true,
|
||||
pieces: true,
|
||||
},
|
||||
},
|
||||
pieces: true,
|
||||
documents: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findAll() {
|
||||
return this.prisma.composant.findMany({
|
||||
include: {
|
||||
machine: true,
|
||||
parentComposant: true,
|
||||
typeComposant: true,
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
sousComposants: {
|
||||
include: {
|
||||
typeComposant: true,
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
pieces: {
|
||||
include: {
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
pieces: {
|
||||
include: {
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
documents: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
return this.prisma.composant.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
machine: true,
|
||||
parentComposant: true,
|
||||
typeComposant: true,
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
sousComposants: {
|
||||
include: {
|
||||
typeComposant: true,
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
pieces: {
|
||||
include: {
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
pieces: {
|
||||
include: {
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
documents: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findByMachine(machineId: string) {
|
||||
return this.prisma.composant.findMany({
|
||||
where: { machineId },
|
||||
include: {
|
||||
machine: true,
|
||||
parentComposant: true,
|
||||
typeComposant: true,
|
||||
sousComposants: {
|
||||
include: {
|
||||
typeComposant: true,
|
||||
pieces: true,
|
||||
},
|
||||
},
|
||||
pieces: {
|
||||
include: {
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
documents: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findHierarchy(machineId: string) {
|
||||
// Récupérer tous les composants de premier niveau (sans parent)
|
||||
const rootComposants = await this.prisma.composant.findMany({
|
||||
where: {
|
||||
machineId,
|
||||
parentComposantId: null
|
||||
},
|
||||
include: {
|
||||
typeComposant: true,
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
sousComposants: {
|
||||
include: {
|
||||
typeComposant: true,
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
pieces: {
|
||||
include: {
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
sousComposants: {
|
||||
include: {
|
||||
typeComposant: true,
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
pieces: {
|
||||
include: {
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
pieces: {
|
||||
include: {
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return rootComposants;
|
||||
}
|
||||
|
||||
async update(id: string, updateComposantDto: UpdateComposantDto) {
|
||||
return this.prisma.composant.update({
|
||||
where: { id },
|
||||
data: updateComposantDto,
|
||||
include: {
|
||||
machine: true,
|
||||
parentComposant: true,
|
||||
typeComposant: true,
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
sousComposants: {
|
||||
include: {
|
||||
typeComposant: true,
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
pieces: {
|
||||
include: {
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
pieces: {
|
||||
include: {
|
||||
customFieldValues: {
|
||||
include: {
|
||||
customField: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
documents: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
return this.prisma.composant.delete({
|
||||
where: { id },
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user