26 lines
748 B
TypeScript
26 lines
748 B
TypeScript
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
import { Users } from '@prisma/client';
|
|
import { PrismaService } from 'src/prisma/prisma.service';
|
|
|
|
@Injectable()
|
|
export abstract class AbstractUserService {
|
|
constructor(protected readonly prisma: PrismaService) {}
|
|
|
|
findAll(): Promise<Users[]> {
|
|
return this.prisma.users.findMany();
|
|
}
|
|
|
|
async findOne(user_id: number): Promise<Users> {
|
|
const user = await this.prisma.users.findUnique({ where: { user_id } });
|
|
if (!user) {
|
|
throw new NotFoundException(`User #${user_id} not found`);
|
|
}
|
|
return user;
|
|
}
|
|
|
|
async remove(user_id: number): Promise<Users> {
|
|
await this.findOne(user_id);
|
|
return this.prisma.users.delete({ where: { user_id } });
|
|
}
|
|
}
|