chore(repo): restructure as monorepo with server and client workspaces
- move NestJS app into server/ subdirectory - add client/ React+TypeScript (Vite) app with Hello World - update docker-compose to build and run both services - add root package.json declaring npm workspaces - update .gitignore to cover node_modules and dist at all depths
This commit is contained in:
1 parent
afc4627353
commit
5cc16725fb
88 files changed
+12637
-405
No files matched your search
@@ -0,0 +1,67 @@
|
||||
import {
|
||||
ConflictException,
|
||||
Injectable,
|
||||
NotFoundException,
|
||||
} from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { Repository } from "typeorm";
|
||||
import { EnvironmentEntity } from "./environment.entity";
|
||||
import { CreateEnvironmentDto } from "./dto/create-environment.dto";
|
||||
import { UpdateEnvironmentDto } from "./dto/update-environment.dto";
|
||||
import {
|
||||
PaginationQueryDto,
|
||||
PaginatedResult,
|
||||
} from "../common/dto/pagination.dto";
|
||||
|
||||
export type EnvironmentOrderBy = "id" | "name" | "createdAt" | "updatedAt";
|
||||
|
||||
@Injectable()
|
||||
export class EnvironmentService {
|
||||
constructor(
|
||||
@InjectRepository(EnvironmentEntity)
|
||||
private readonly repo: Repository<EnvironmentEntity>,
|
||||
) {}
|
||||
|
||||
async create(dto: CreateEnvironmentDto): Promise<EnvironmentEntity> {
|
||||
const existing = await this.repo.findOneBy({ name: dto.name });
|
||||
if (existing) {
|
||||
throw new ConflictException(`Environment "${dto.name}" already exists`);
|
||||
}
|
||||
return this.repo.save(this.repo.create(dto));
|
||||
}
|
||||
|
||||
async findAll(
|
||||
query: PaginationQueryDto<EnvironmentOrderBy> = {},
|
||||
): Promise<PaginatedResult<EnvironmentEntity>> {
|
||||
const page = query.page ?? 1;
|
||||
const limit = query.limit ?? 20;
|
||||
const orderBy = query.orderBy ?? "id";
|
||||
const orderDir = query.orderDir ?? "ASC";
|
||||
const [data, total] = await this.repo.findAndCount({
|
||||
order: { [orderBy]: orderDir },
|
||||
skip: (page - 1) * limit,
|
||||
take: limit,
|
||||
});
|
||||
return { data, total, page, limit };
|
||||
}
|
||||
|
||||
async findOne(id: number): Promise<EnvironmentEntity> {
|
||||
const env = await this.repo.findOneBy({ id });
|
||||
if (!env) throw new NotFoundException(`Environment ${id} not found`);
|
||||
return env;
|
||||
}
|
||||
|
||||
async update(
|
||||
id: number,
|
||||
dto: UpdateEnvironmentDto,
|
||||
): Promise<EnvironmentEntity> {
|
||||
const env = await this.findOne(id);
|
||||
Object.assign(env, dto);
|
||||
return this.repo.save(env);
|
||||
}
|
||||
|
||||
async remove(id: number): Promise<void> {
|
||||
await this.findOne(id);
|
||||
await this.repo.delete(id);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user