web:api:prisma-fastify:p2-b

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
web:api:prisma-fastify:p2-b [2026/03/20 13:25] jcheronweb: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<T> +type CrudModel = 
-  constructor(private model{}+    findMany: (args?: any=> any 
 +    findUnique: (args: any) => any 
 +    create: (args: any) => any 
 +    update: (args: any) => any 
 +    delete: (args: any) => any 
 +}
  
-  findAll() +class BaseService<T extends CrudModel> 
-    return this.model.findMany() +    constructor(private model: T{}
-  }+
  
-  findById(id: string) { +    findAll() { 
-    return this.model.findUnique({ where: { id } }+        return this.model.findMany() 
-  }+    }
  
-  create(dataany) { +    findById(idstring) { 
-    return this.model.create({ data }) +        return this.model.findUnique({ where: { id } }) 
-  }+    }
  
-  update(id: string, data: any) { +    create(data: any) { 
-    return this.model.update({ +        return this.model.create({ data }) 
-      where: { id }, +    }
-      data +
-    }) +
-  }+
  
-  delete(id: string) { +    update(id: string, data: any) { 
-    return this.model.delete({ +        return this.model.update({ 
-      where: { id } +            where: { id }, 
-    }) +            data 
-  }+        }) 
 +    
 + 
 +    delete(id: string) { 
 +        return this.model.delete({ 
 +            where: { id } 
 +        }) 
 +    }
 } }
 </sxh> </sxh>
  • web/api/prisma-fastify/p2-b.1774009554.txt.gz
  • Dernière modification : il y a 7 semaines
  • de jcheron