work-hub-server/apps/api/src/project/project.repository.ts

37 lines
1 KiB
TypeScript

import { Injectable } from "@nestjs/common";
import { projects, eq, ProjectInsertDTO, ProjectUpdateDTO } from "@workspace/schema";
import { DrizzleService } from "../database/drizzle.service";
@Injectable()
export class ProjectRepository {
constructor(private readonly drizzle: DrizzleService) {}
private get db() {
return this.drizzle.db;
}
async create(body: ProjectInsertDTO) {
const [project] = await this.db.insert(projects).values(body).returning();
return project;
}
findAll() {
return this.db.select().from(projects);
}
async findOne(id: string) {
const [project] = await this.db.select().from(projects).where(eq(projects.id, id));
return project;
}
async update(id: string, body: ProjectUpdateDTO) {
const [project] = await this.db.update(projects).set(body).where(eq(projects.id, id)).returning();
return project;
}
async remove(id: string) {
const [project] = await this.db.delete(projects).where(eq(projects.id, id)).returning();
return project;
}
}