introduce TRPC and service layer
This commit is contained in:
29
lib/services/notes.service.ts
Normal file
29
lib/services/notes.service.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
export default class NotesService {
|
||||
private prisma: PrismaClient;
|
||||
|
||||
constructor( prisma: PrismaClient) {
|
||||
this.prisma = prisma;
|
||||
}
|
||||
|
||||
async getAllNotes() {
|
||||
return this.prisma.note.findMany();
|
||||
}
|
||||
|
||||
async getNotesForAccountId(account_id: number) {
|
||||
return this.prisma.note.findMany({ where: { account_id } });
|
||||
}
|
||||
|
||||
async createNote( account_id: number, note_text: string ) {
|
||||
return this.prisma.note.create({ data: { account_id, note_text }});
|
||||
}
|
||||
|
||||
async updateNote(id: number, note_text: string) {
|
||||
return this.prisma.note.update({ where: { id }, data: { note_text } });
|
||||
}
|
||||
|
||||
async deleteNote(id: number) {
|
||||
return this.prisma.note.delete({ where: { id } });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user