feat: Add Model gestion for piece and component
This commit is contained in:
@@ -1,6 +1,18 @@
|
||||
import { Controller, Get, Post, Patch, Delete, Param, Body, Query } from '@nestjs/common'
|
||||
import { ConstructeursService } from './constructeurs.service'
|
||||
import { CreateConstructeurDto, UpdateConstructeurDto } from '../shared/dto/constructeur.dto'
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Patch,
|
||||
Delete,
|
||||
Param,
|
||||
Body,
|
||||
Query,
|
||||
} from '@nestjs/common';
|
||||
import { ConstructeursService } from './constructeurs.service';
|
||||
import {
|
||||
CreateConstructeurDto,
|
||||
UpdateConstructeurDto,
|
||||
} from '../shared/dto/constructeur.dto';
|
||||
|
||||
@Controller('constructeurs')
|
||||
export class ConstructeursController {
|
||||
@@ -8,26 +20,26 @@ export class ConstructeursController {
|
||||
|
||||
@Post()
|
||||
create(@Body() payload: CreateConstructeurDto) {
|
||||
return this.constructeursService.create(payload)
|
||||
return this.constructeursService.create(payload);
|
||||
}
|
||||
|
||||
@Get()
|
||||
findAll(@Query('search') search?: string) {
|
||||
return this.constructeursService.findAll(search)
|
||||
return this.constructeursService.findAll(search);
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.constructeursService.findOne(id)
|
||||
return this.constructeursService.findOne(id);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() payload: UpdateConstructeurDto) {
|
||||
return this.constructeursService.update(id, payload)
|
||||
return this.constructeursService.update(id, payload);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.constructeursService.remove(id)
|
||||
return this.constructeursService.remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Module } from '@nestjs/common'
|
||||
import { ConstructeursService } from './constructeurs.service'
|
||||
import { ConstructeursController } from './constructeurs.controller'
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConstructeursService } from './constructeurs.service';
|
||||
import { ConstructeursController } from './constructeurs.controller';
|
||||
|
||||
@Module({
|
||||
controllers: [ConstructeursController],
|
||||
|
||||
@@ -1,23 +1,26 @@
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { PrismaService } from '../prisma/prisma.service'
|
||||
import { CreateConstructeurDto, UpdateConstructeurDto } from '../shared/dto/constructeur.dto'
|
||||
import { Prisma } from '@prisma/client'
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import {
|
||||
CreateConstructeurDto,
|
||||
UpdateConstructeurDto,
|
||||
} from '../shared/dto/constructeur.dto';
|
||||
import { Prisma } from '@prisma/client';
|
||||
|
||||
@Injectable()
|
||||
export class ConstructeursService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
private buildSearchWhere(search?: string): Prisma.ConstructeurWhereInput {
|
||||
if (!search) return {}
|
||||
const term = search.trim()
|
||||
if (!term) return {}
|
||||
if (!search) return {};
|
||||
const term = search.trim();
|
||||
if (!term) return {};
|
||||
return {
|
||||
OR: [
|
||||
{ name: { contains: term, mode: 'insensitive' } },
|
||||
{ email: { contains: term, mode: 'insensitive' } },
|
||||
{ phone: { contains: term, mode: 'insensitive' } },
|
||||
],
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async create(data: CreateConstructeurDto) {
|
||||
@@ -28,20 +31,20 @@ export class ConstructeursService {
|
||||
email: data.email?.trim(),
|
||||
phone: data.phone?.trim(),
|
||||
},
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
async findAll(search?: string) {
|
||||
return this.prisma.constructeur.findMany({
|
||||
where: this.buildSearchWhere(search),
|
||||
orderBy: { name: 'asc' },
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
async findOne(id: string) {
|
||||
return this.prisma.constructeur.findUnique({
|
||||
where: { id },
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
async update(id: string, data: UpdateConstructeurDto) {
|
||||
@@ -53,12 +56,12 @@ export class ConstructeursService {
|
||||
email: data.email?.trim(),
|
||||
phone: data.phone?.trim(),
|
||||
},
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
async remove(id: string) {
|
||||
return this.prisma.constructeur.delete({
|
||||
where: { id },
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user