feat: Modules de fonctionnalités avancées - Ajout des modules Documents et Champs personnalisés pour la gestion des fichiers et métadonnées
This commit is contained in:
21
src/documents/documents.controller.spec.ts
Normal file
21
src/documents/documents.controller.spec.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { DocumentsController } from './documents.controller';
|
||||
import { DocumentsService } from './documents.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
describe('DocumentsController', () => {
|
||||
let controller: DocumentsController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [DocumentsController],
|
||||
providers: [DocumentsService, PrismaService],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<DocumentsController>(DocumentsController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
48
src/documents/documents.controller.ts
Normal file
48
src/documents/documents.controller.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
|
||||
import { DocumentsService } from './documents.service';
|
||||
import { CreateDocumentDto, UpdateDocumentDto } from '../shared/dto/document.dto';
|
||||
|
||||
@Controller('documents')
|
||||
export class DocumentsController {
|
||||
constructor(private readonly documentsService: DocumentsService) {}
|
||||
|
||||
@Post()
|
||||
create(@Body() createDocumentDto: CreateDocumentDto) {
|
||||
return this.documentsService.create(createDocumentDto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll() {
|
||||
return this.documentsService.findAll();
|
||||
}
|
||||
|
||||
@Get('machine/:machineId')
|
||||
findByMachine(@Param('machineId') machineId: string) {
|
||||
return this.documentsService.findByMachine(machineId);
|
||||
}
|
||||
|
||||
@Get('composant/:composantId')
|
||||
findByComposant(@Param('composantId') composantId: string) {
|
||||
return this.documentsService.findByComposant(composantId);
|
||||
}
|
||||
|
||||
@Get('piece/:pieceId')
|
||||
findByPiece(@Param('pieceId') pieceId: string) {
|
||||
return this.documentsService.findByPiece(pieceId);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.documentsService.findOne(id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() updateDocumentDto: UpdateDocumentDto) {
|
||||
return this.documentsService.update(id, updateDocumentDto);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.documentsService.remove(id);
|
||||
}
|
||||
}
|
||||
9
src/documents/documents.module.ts
Normal file
9
src/documents/documents.module.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { DocumentsController } from './documents.controller';
|
||||
import { DocumentsService } from './documents.service';
|
||||
|
||||
@Module({
|
||||
controllers: [DocumentsController],
|
||||
providers: [DocumentsService]
|
||||
})
|
||||
export class DocumentsModule {}
|
||||
19
src/documents/documents.service.spec.ts
Normal file
19
src/documents/documents.service.spec.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { DocumentsService } from './documents.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
describe('DocumentsService', () => {
|
||||
let service: DocumentsService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [DocumentsService, PrismaService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<DocumentsService>(DocumentsService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
91
src/documents/documents.service.ts
Normal file
91
src/documents/documents.service.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { CreateDocumentDto, UpdateDocumentDto } from '../shared/dto/document.dto';
|
||||
|
||||
@Injectable()
|
||||
export class DocumentsService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async create(createDocumentDto: CreateDocumentDto) {
|
||||
return this.prisma.document.create({
|
||||
data: createDocumentDto,
|
||||
include: {
|
||||
machine: true,
|
||||
composant: true,
|
||||
piece: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findAll() {
|
||||
return this.prisma.document.findMany({
|
||||
include: {
|
||||
machine: true,
|
||||
composant: true,
|
||||
piece: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
return this.prisma.document.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
machine: true,
|
||||
composant: true,
|
||||
piece: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findByMachine(machineId: string) {
|
||||
return this.prisma.document.findMany({
|
||||
where: { machineId },
|
||||
include: {
|
||||
machine: true,
|
||||
composant: true,
|
||||
piece: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findByComposant(composantId: string) {
|
||||
return this.prisma.document.findMany({
|
||||
where: { composantId },
|
||||
include: {
|
||||
machine: true,
|
||||
composant: true,
|
||||
piece: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async findByPiece(pieceId: string) {
|
||||
return this.prisma.document.findMany({
|
||||
where: { pieceId },
|
||||
include: {
|
||||
machine: true,
|
||||
composant: true,
|
||||
piece: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async update(id: string, updateDocumentDto: UpdateDocumentDto) {
|
||||
return this.prisma.document.update({
|
||||
where: { id },
|
||||
data: updateDocumentDto,
|
||||
include: {
|
||||
machine: true,
|
||||
composant: true,
|
||||
piece: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
return this.prisma.document.delete({
|
||||
where: { id },
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user