Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente | |||
| web:api:prisma-fastify:p2-b [2026/03/20 13:25] – jcheron | web:api:prisma-fastify:p2-b [2026/03/20 13:50] (Version actuelle) – [Factorisation] jcheron | ||
|---|---|---|---|
| Ligne 123: | Ligne 123: | ||
| Pour le CRUD : | Pour le CRUD : | ||
| <sxh ts> | <sxh ts> | ||
| - | class BaseService< | + | type CrudModel = { |
| - | | + | |
| + | findUnique: (args: any) => any | ||
| + | create: (args: any) => any | ||
| + | update: (args: any) => any | ||
| + | delete: (args: any) => any | ||
| + | } | ||
| - | findAll() | + | class BaseService< |
| - | | + | |
| - | | + | |
| - | findById(id: string) { | + | findAll() { |
| - | return this.model.findUnique({ where: { id } }) | + | return this.model.findMany() |
| - | } | + | } |
| - | create(data: any) { | + | findById(id: string) { |
| - | return this.model.create({ data }) | + | return this.model.findUnique({ where: { id } }) |
| - | } | + | } |
| - | update(id: string, | + | create(data: any) { |
| - | return this.model.update({ | + | return this.model.create({ data }) |
| - | where: { id }, | + | } |
| - | | + | |
| - | | + | |
| - | } | + | |
| - | delete(id: string) { | + | update(id: string, data: any) { |
| - | return this.model.delete({ | + | return this.model.update({ |
| - | where: { id } | + | where: { id }, |
| - | }) | + | data |
| - | } | + | }) |
| + | | ||
| + | |||
| + | delete(id: string) { | ||
| + | | ||
| + | where: { id } | ||
| + | }) | ||
| + | } | ||
| } | } | ||
| </ | </ | ||