add organization management and refine source repository view
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2026-07-07 11:56:42 +09:00
parent 321b7c316e
commit 895e56088c
7 changed files with 268 additions and 0 deletions
+114
View File
@@ -0,0 +1,114 @@
import { ConflictException, Injectable, NotFoundException } from '@nestjs/common';
import { Prisma } from '@prisma/auth-client';
import { AuthPrismaService } from '../auth-prisma/auth-prisma.service';
import { CreateOrganizationDto, UpdateOrganizationDto } from './dto';
@Injectable()
export class OrganizationsService {
constructor(private readonly authPrisma: AuthPrismaService) {}
async list() {
const organizations = await this.authPrisma.organization.findMany({
where: { isActive: true },
orderBy: [{ type: 'asc' }, { name: 'asc' }],
select: {
id: true,
name: true,
type: true,
domain: true,
createdAt: true,
},
});
return { organizations };
}
async create(body: CreateOrganizationDto) {
try {
const organization = await this.authPrisma.organization.create({
data: {
name: body.name.trim(),
type: body.type,
domain: body.domain?.trim() || null,
},
select: {
id: true,
name: true,
type: true,
domain: true,
createdAt: true,
},
});
return { organization };
} catch (error) {
if (
error instanceof Prisma.PrismaClientKnownRequestError &&
error.code === 'P2002'
) {
throw new ConflictException('이미 등록된 조직입니다.');
}
throw error;
}
}
async update(id: string, body: UpdateOrganizationDto) {
try {
const organization = await this.authPrisma.organization.update({
where: { id },
data: {
...(body.name !== undefined ? { name: body.name.trim() } : {}),
...(body.type !== undefined ? { type: body.type } : {}),
...(body.domain !== undefined ? { domain: body.domain?.trim() || null } : {}),
},
select: {
id: true,
name: true,
type: true,
domain: true,
createdAt: true,
},
});
return { organization };
} catch (error) {
if (
error instanceof Prisma.PrismaClientKnownRequestError &&
error.code === 'P2025'
) {
throw new NotFoundException('조직을 찾을 수 없습니다.');
}
if (
error instanceof Prisma.PrismaClientKnownRequestError &&
error.code === 'P2002'
) {
throw new ConflictException('이미 등록된 조직입니다.');
}
throw error;
}
}
async remove(id: string) {
try {
await this.authPrisma.organization.update({
where: { id },
data: { isActive: false },
});
return { ok: true };
} catch (error) {
if (
error instanceof Prisma.PrismaClientKnownRequestError &&
error.code === 'P2025'
) {
throw new NotFoundException('조직을 찾을 수 없습니다.');
}
throw error;
}
}
}