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:
@@ -0,0 +1,21 @@
|
||||
import { ApiProperty } from "@nestjs/swagger";
|
||||
import { IsNotEmpty, IsObject, IsString } from "class-validator";
|
||||
import { EnvironmentUrls } from "../environment.entity";
|
||||
|
||||
export class CreateEnvironmentDto {
|
||||
@ApiProperty({ example: "liquio-diia-stg" })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
name: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: "Map of URL identifiers to URL strings",
|
||||
example: {
|
||||
id_url: "https://id-liquio-diia-stg.kitsoft.ua/",
|
||||
cabinet_url: "https://cabinet-liquio-diia-stg.kitsoft.ua/",
|
||||
admin_url: "https://admin-liquio-diia-stg.kitsoft.ua/",
|
||||
},
|
||||
})
|
||||
@IsObject()
|
||||
urls: EnvironmentUrls;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from "@nestjs/swagger";
|
||||
import { CreateEnvironmentDto } from "./create-environment.dto";
|
||||
|
||||
export class UpdateEnvironmentDto extends PartialType(CreateEnvironmentDto) {}
|
||||
@@ -0,0 +1,67 @@
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpCode,
|
||||
Param,
|
||||
ParseIntPipe,
|
||||
Patch,
|
||||
Post,
|
||||
Query,
|
||||
} from "@nestjs/common";
|
||||
import { ApiOperation, ApiResponse, ApiTags } from "@nestjs/swagger";
|
||||
import { EnvironmentService } from "./environment.service";
|
||||
import { CreateEnvironmentDto } from "./dto/create-environment.dto";
|
||||
import { UpdateEnvironmentDto } from "./dto/update-environment.dto";
|
||||
import { PaginationQueryDto } from "../common/dto/pagination.dto";
|
||||
import { EnvironmentOrderBy } from "./environment.service";
|
||||
|
||||
@ApiTags("environments")
|
||||
@Controller("environments")
|
||||
export class EnvironmentController {
|
||||
constructor(private readonly environmentService: EnvironmentService) {}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: "Create a new environment" })
|
||||
@ApiResponse({ status: 201, description: "Environment created" })
|
||||
@ApiResponse({ status: 409, description: "Environment name already exists" })
|
||||
create(@Body() dto: CreateEnvironmentDto) {
|
||||
return this.environmentService.create(dto);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: "List all environments (paginated)" })
|
||||
@ApiResponse({ status: 200, description: "Paginated environments" })
|
||||
findAll(@Query() query: PaginationQueryDto<EnvironmentOrderBy>) {
|
||||
return this.environmentService.findAll(query);
|
||||
}
|
||||
|
||||
@Get(":id")
|
||||
@ApiOperation({ summary: "Get environment by ID" })
|
||||
@ApiResponse({ status: 200, description: "Environment record" })
|
||||
@ApiResponse({ status: 404, description: "Environment not found" })
|
||||
findOne(@Param("id", ParseIntPipe) id: number) {
|
||||
return this.environmentService.findOne(id);
|
||||
}
|
||||
|
||||
@Patch(":id")
|
||||
@ApiOperation({ summary: "Update an environment" })
|
||||
@ApiResponse({ status: 200, description: "Environment updated" })
|
||||
@ApiResponse({ status: 404, description: "Environment not found" })
|
||||
update(
|
||||
@Param("id", ParseIntPipe) id: number,
|
||||
@Body() dto: UpdateEnvironmentDto,
|
||||
) {
|
||||
return this.environmentService.update(id, dto);
|
||||
}
|
||||
|
||||
@Delete(":id")
|
||||
@HttpCode(204)
|
||||
@ApiOperation({ summary: "Delete an environment" })
|
||||
@ApiResponse({ status: 204, description: "Environment deleted" })
|
||||
@ApiResponse({ status: 404, description: "Environment not found" })
|
||||
remove(@Param("id", ParseIntPipe) id: number) {
|
||||
return this.environmentService.remove(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import {
|
||||
Entity,
|
||||
PrimaryGeneratedColumn,
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
UpdateDateColumn,
|
||||
} from "typeorm";
|
||||
|
||||
export interface EnvironmentUrls {
|
||||
id_url?: string;
|
||||
cabinet_url?: string;
|
||||
admin_url?: string;
|
||||
[key: string]: string | undefined;
|
||||
}
|
||||
|
||||
@Entity("environments")
|
||||
export class EnvironmentEntity {
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Column({ unique: true })
|
||||
name: string;
|
||||
|
||||
@Column("simple-json")
|
||||
urls: EnvironmentUrls;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt: Date;
|
||||
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
import { EnvironmentEntity } from "./environment.entity";
|
||||
import { EnvironmentService } from "./environment.service";
|
||||
import { EnvironmentController } from "./environment.controller";
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([EnvironmentEntity])],
|
||||
controllers: [EnvironmentController],
|
||||
providers: [EnvironmentService],
|
||||
exports: [EnvironmentService],
|
||||
})
|
||||
export class EnvironmentModule {}
|
||||
@@ -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