Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 78f3578098 | |||
| e811208773 |
+6
-2
@@ -8,11 +8,15 @@ RUN npm run build
|
||||
FROM node:22-bookworm-slim AS runner
|
||||
WORKDIR /app
|
||||
ENV NODE_ENV=production
|
||||
ARG DOCKER_VERSION=27.5.1
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends ca-certificates curl git docker.io binutils \
|
||||
&& apt-get install -y --no-install-recommends ca-certificates curl git \
|
||||
&& curl -fsSL "https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_VERSION}.tgz" \
|
||||
| tar -xz -C /tmp \
|
||||
&& install -m 0755 /tmp/docker/docker /usr/local/bin/docker \
|
||||
&& curl -fsSL -o /usr/local/bin/kubectl "https://dl.k8s.io/release/v1.30.0/bin/linux/amd64/kubectl" \
|
||||
&& chmod 0755 /usr/local/bin/kubectl \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
&& rm -rf /tmp/docker /var/lib/apt/lists/*
|
||||
COPY package*.json ./
|
||||
RUN npm ci --omit=dev
|
||||
COPY --from=builder /app/dist ./dist
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:17-alpine
|
||||
container_name: atnmy-stdo-adm-v2-postgres
|
||||
environment:
|
||||
POSTGRES_DB: studio_admin
|
||||
POSTGRES_USER: studio_admin
|
||||
POSTGRES_PASSWORD: future1234!@
|
||||
ports:
|
||||
- "5436:5432"
|
||||
volumes:
|
||||
- atnmy-stdo-adm-v2-postgres:/var/lib/postgresql/data
|
||||
restart: unless-stopped
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U studio_admin -d studio_admin"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
|
||||
volumes:
|
||||
atnmy-stdo-adm-v2-postgres:
|
||||
@@ -108,18 +108,22 @@ model UserLicense {
|
||||
}
|
||||
|
||||
model Organization {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
name String
|
||||
type OrganizationType @default(OTHER)
|
||||
domain String?
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
name String
|
||||
type OrganizationType @default(OTHER)
|
||||
domain String?
|
||||
defaultLicenseCode String? @map("default_license_code")
|
||||
isActive Boolean @default(true) @map("is_active")
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
||||
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz(3)
|
||||
affiliations UserAffiliation[]
|
||||
isActive Boolean @default(true) @map("is_active")
|
||||
createdById String? @map("created_by_id") @db.Uuid
|
||||
createdByName String? @map("created_by_name")
|
||||
createdByEmail String? @map("created_by_email")
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
||||
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz(3)
|
||||
affiliations UserAffiliation[]
|
||||
|
||||
@@unique([name, type])
|
||||
@@index([isActive, type])
|
||||
@@index([createdByEmail])
|
||||
@@map("organizations")
|
||||
}
|
||||
|
||||
|
||||
@@ -46,16 +46,20 @@ model LauncherTerm {
|
||||
}
|
||||
|
||||
model LauncherManualDocument {
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
appKey String @map("app_key")
|
||||
title String
|
||||
body String
|
||||
isPublished Boolean @default(true) @map("is_published")
|
||||
sortOrder Int @default(0) @map("sort_order")
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
||||
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz(3)
|
||||
id String @id @default(uuid()) @db.Uuid
|
||||
appKey String @map("app_key")
|
||||
title String
|
||||
body String
|
||||
isPublished Boolean @default(true) @map("is_published")
|
||||
sortOrder Int @default(0) @map("sort_order")
|
||||
createdById String? @map("created_by_id") @db.Uuid
|
||||
createdByName String? @map("created_by_name")
|
||||
createdByEmail String? @map("created_by_email")
|
||||
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
||||
updatedAt DateTime @updatedAt @map("updated_at") @db.Timestamptz(3)
|
||||
|
||||
@@index([appKey, isPublished, sortOrder])
|
||||
@@index([createdByEmail])
|
||||
@@map("launcher_manual_documents")
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
ALTER TABLE "launcher_manual_documents"
|
||||
ADD COLUMN IF NOT EXISTS "created_by_id" UUID,
|
||||
ADD COLUMN IF NOT EXISTS "created_by_name" TEXT,
|
||||
ADD COLUMN IF NOT EXISTS "created_by_email" TEXT;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS "launcher_manual_documents_created_by_email_idx"
|
||||
ON "launcher_manual_documents"("created_by_email");
|
||||
@@ -0,0 +1,9 @@
|
||||
DO $$
|
||||
BEGIN
|
||||
IF to_regclass('public.organizations') IS NOT NULL THEN
|
||||
ALTER TABLE "organizations"
|
||||
ADD COLUMN IF NOT EXISTS "created_by_id" UUID,
|
||||
ADD COLUMN IF NOT EXISTS "created_by_name" TEXT,
|
||||
ADD COLUMN IF NOT EXISTS "created_by_email" TEXT;
|
||||
END IF;
|
||||
END $$;
|
||||
@@ -0,0 +1,9 @@
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
export function getAdminAvatarUrl(adminId: string | null | undefined, configService: ConfigService) {
|
||||
const publicBaseUrl = configService.get<string>('R2_PUBLIC_BASE_URL')?.replace(/\/+$/, '');
|
||||
if (!adminId || !publicBaseUrl) return null;
|
||||
|
||||
const prefix = configService.get<string>('R2_PUBLIC_FILE_PREFIX', 'studio-files/public');
|
||||
return `${publicBaseUrl}/${prefix.replace(/^\/+|\/+$/g, '')}/admins/${adminId}/avatar`;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { ConfigService } from '@nestjs/config';
|
||||
|
||||
import { GiteaService } from '../gitea/gitea.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { getAdminAvatarUrl } from './admin-avatar';
|
||||
import { AdminRole } from './admin-role';
|
||||
import {
|
||||
CreateAdminSshKeyDto,
|
||||
@@ -334,13 +335,6 @@ export class AdminsService {
|
||||
}
|
||||
}
|
||||
|
||||
function getAdminAvatarUrl(adminId: string, configService: ConfigService) {
|
||||
const publicBaseUrl = configService.get<string>('R2_PUBLIC_BASE_URL')?.replace(/\/+$/, '');
|
||||
if (!publicBaseUrl) return null;
|
||||
const prefix = configService.get<string>('R2_PUBLIC_FILE_PREFIX', 'studio-files/public');
|
||||
return `${publicBaseUrl}/${prefix.replace(/^\/+|\/+$/g, '')}/admins/${adminId}/avatar`;
|
||||
}
|
||||
|
||||
const adminSelect = {
|
||||
id: true,
|
||||
email: true,
|
||||
|
||||
@@ -2,13 +2,12 @@ import { Module } from '@nestjs/common';
|
||||
|
||||
import { LauncherModule } from '../launcher/launcher.module';
|
||||
import { PrismaModule } from '../prisma/prisma.module';
|
||||
import { AuthPrismaModule } from '../auth-prisma/auth-prisma.module';
|
||||
import { AppsController } from './apps.controller';
|
||||
import { AppsService } from './apps.service';
|
||||
import { BuildRunnerService } from './build-runner.service';
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule, LauncherModule, AuthPrismaModule],
|
||||
imports: [PrismaModule, LauncherModule],
|
||||
controllers: [AppsController],
|
||||
providers: [AppsService, BuildRunnerService],
|
||||
})
|
||||
|
||||
@@ -8,10 +8,9 @@ import * as path from 'node:path';
|
||||
import { promisify } from 'node:util';
|
||||
|
||||
import { LinkComponentSourceDto } from '../gitea/dto';
|
||||
import { getAdminAvatarUrl } from '../admins/admin-avatar';
|
||||
import { LauncherService } from '../launcher/launcher.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { AuthPrismaService } from '../auth-prisma/auth-prisma.service';
|
||||
import { getUserAvatarUrl } from '../users/users.service';
|
||||
import { BuildRunnerService } from './build-runner.service';
|
||||
import {
|
||||
CreateAppComponentDto,
|
||||
@@ -46,7 +45,6 @@ export class AppsService {
|
||||
private readonly configService: ConfigService,
|
||||
private readonly buildRunnerService: BuildRunnerService,
|
||||
private readonly launcherService: LauncherService,
|
||||
private readonly authPrisma: AuthPrismaService,
|
||||
) {}
|
||||
|
||||
private requesterData(requester?: AdminRequester) {
|
||||
@@ -59,31 +57,11 @@ export class AppsService {
|
||||
: {};
|
||||
}
|
||||
|
||||
private async withRequesterAvatars<T extends { requestedByEmail?: string | null }>(items: T[]) {
|
||||
const emails = [...new Set(items.map((item) => item.requestedByEmail).filter((email): email is string => Boolean(email)))];
|
||||
if (emails.length === 0) return items.map((item) => ({ ...item, requestedByAvatarUrl: null }));
|
||||
|
||||
const users = await this.authPrisma.user.findMany({
|
||||
where: { email: { in: emails } },
|
||||
select: {
|
||||
id: true,
|
||||
email: true,
|
||||
profileImageMime: true,
|
||||
},
|
||||
});
|
||||
const userByEmail = new Map(users.map((user) => [user.email, user]));
|
||||
const authBaseUrl = this.configService.get<string>('AUTH_PUBLIC_URL')
|
||||
?? this.configService.get<string>('ATNMY_AUTH_URL')
|
||||
?? this.configService.get<string>('AUTH_EXTERNAL_URL')
|
||||
?? 'https://auth.autonomystudio.net';
|
||||
|
||||
return items.map((item) => {
|
||||
const user = item.requestedByEmail ? userByEmail.get(item.requestedByEmail) : null;
|
||||
return {
|
||||
...item,
|
||||
requestedByAvatarUrl: getUserAvatarUrl(user?.id ?? '', user?.profileImageMime, authBaseUrl),
|
||||
};
|
||||
});
|
||||
private withRequesterAvatars<T extends { requestedById?: string | null }>(items: T[]) {
|
||||
return items.map((item) => ({
|
||||
...item,
|
||||
requestedByAvatarUrl: getAdminAvatarUrl(item.requestedById, this.configService),
|
||||
}));
|
||||
}
|
||||
|
||||
async listApps() {
|
||||
|
||||
@@ -2,12 +2,11 @@ import { Module } from '@nestjs/common';
|
||||
|
||||
import { PrismaModule } from '../prisma/prisma.module';
|
||||
import { LauncherPrismaModule } from '../launcher-prisma/launcher-prisma.module';
|
||||
import { AuthPrismaModule } from '../auth-prisma/auth-prisma.module';
|
||||
import { LauncherController } from './launcher.controller';
|
||||
import { LauncherService } from './launcher.service';
|
||||
|
||||
@Module({
|
||||
imports: [PrismaModule, LauncherPrismaModule, AuthPrismaModule],
|
||||
imports: [PrismaModule, LauncherPrismaModule],
|
||||
controllers: [LauncherController],
|
||||
providers: [LauncherService],
|
||||
exports: [LauncherService],
|
||||
|
||||
@@ -10,8 +10,7 @@ import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
|
||||
|
||||
import { LauncherPrismaService } from '../launcher-prisma/launcher-prisma.service';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { AuthPrismaService } from '../auth-prisma/auth-prisma.service';
|
||||
import { getUserAvatarUrl } from '../users/users.service';
|
||||
import { getAdminAvatarUrl } from '../admins/admin-avatar';
|
||||
import {
|
||||
CreateLauncherAppLinkDto,
|
||||
CreateLauncherBuildJobDto,
|
||||
@@ -63,7 +62,6 @@ export class LauncherService {
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly launcherPrisma: LauncherPrismaService,
|
||||
private readonly configService: ConfigService,
|
||||
private readonly authPrisma: AuthPrismaService,
|
||||
) {}
|
||||
|
||||
async listVersions() {
|
||||
@@ -453,31 +451,11 @@ export class LauncherService {
|
||||
});
|
||||
}
|
||||
|
||||
private async withLauncherBuildRequesters<T extends { requestedByEmail?: string | null }>(jobs: T[]) {
|
||||
const emails = [...new Set(jobs.map((job) => job.requestedByEmail).filter((email): email is string => Boolean(email)))];
|
||||
if (emails.length === 0) return jobs.map((job) => ({ ...job, requestedByAvatarUrl: null }));
|
||||
|
||||
const users = await this.authPrisma.user.findMany({
|
||||
where: { email: { in: emails } },
|
||||
select: {
|
||||
id: true,
|
||||
email: true,
|
||||
profileImageMime: true,
|
||||
},
|
||||
});
|
||||
const userByEmail = new Map(users.map((user) => [user.email, user]));
|
||||
const authBaseUrl = this.configService.get<string>('AUTH_PUBLIC_URL')
|
||||
?? this.configService.get<string>('ATNMY_AUTH_URL')
|
||||
?? this.configService.get<string>('AUTH_EXTERNAL_URL')
|
||||
?? 'https://auth.autonomystudio.net';
|
||||
|
||||
return jobs.map((job) => {
|
||||
const user = job.requestedByEmail ? userByEmail.get(job.requestedByEmail) : null;
|
||||
return {
|
||||
...job,
|
||||
requestedByAvatarUrl: getUserAvatarUrl(user?.id ?? '', user?.profileImageMime, authBaseUrl),
|
||||
};
|
||||
});
|
||||
private withLauncherBuildRequesters<T extends { requestedById?: string | null }>(jobs: T[]) {
|
||||
return jobs.map((job) => ({
|
||||
...job,
|
||||
requestedByAvatarUrl: getAdminAvatarUrl(job.requestedById, this.configService),
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Body, Controller, Delete, Get, Param, Patch, Post, Query } from '@nestjs/common';
|
||||
import { Body, Controller, Delete, Get, Param, Patch, Post, Query, Req } from '@nestjs/common';
|
||||
|
||||
import { Public } from '../admin-auth/decorators/admin-auth.decorators';
|
||||
import { CreateManualDocumentDto, ListManualDocumentsQuery, UpdateManualDocumentDto } from './dto';
|
||||
@@ -20,8 +20,11 @@ export class ManualsController {
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Body() body: CreateManualDocumentDto) {
|
||||
return this.manualsService.create(body);
|
||||
create(
|
||||
@Body() body: CreateManualDocumentDto,
|
||||
@Req() request: { admin?: { id: string; name: string; email: string } },
|
||||
) {
|
||||
return this.manualsService.create(body, request.admin);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
|
||||
@@ -1,12 +1,34 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { Prisma } from '@prisma/launcher-client';
|
||||
|
||||
import { getAdminAvatarUrl } from '../admins/admin-avatar';
|
||||
import { LauncherPrismaService } from '../launcher-prisma/launcher-prisma.service';
|
||||
import { CreateManualDocumentDto, ListManualDocumentsQuery, UpdateManualDocumentDto } from './dto';
|
||||
|
||||
@Injectable()
|
||||
export class ManualsService {
|
||||
constructor(private readonly launcherPrisma: LauncherPrismaService) {}
|
||||
constructor(
|
||||
private readonly configService: ConfigService,
|
||||
private readonly launcherPrisma: LauncherPrismaService,
|
||||
) {}
|
||||
|
||||
private creatorData(requester?: AdminRequester) {
|
||||
return requester
|
||||
? {
|
||||
createdById: requester.id,
|
||||
createdByName: requester.name,
|
||||
createdByEmail: requester.email,
|
||||
}
|
||||
: {};
|
||||
}
|
||||
|
||||
private withCreatorAvatars<T extends { createdById?: string | null }>(items: T[]) {
|
||||
return items.map((item) => ({
|
||||
...item,
|
||||
createdByAvatarUrl: getAdminAvatarUrl(item.createdById, this.configService),
|
||||
}));
|
||||
}
|
||||
|
||||
async list(query: ListManualDocumentsQuery) {
|
||||
const page = toPositiveInt(query.page, 1);
|
||||
@@ -35,10 +57,10 @@ export class ManualsService {
|
||||
]);
|
||||
|
||||
return {
|
||||
documents: documents.map((document, index) => ({
|
||||
documents: await this.withCreatorAvatars(documents.map((document, index) => ({
|
||||
...document,
|
||||
no: total - ((page - 1) * limit + index),
|
||||
})),
|
||||
}))),
|
||||
total,
|
||||
page,
|
||||
limit,
|
||||
@@ -61,7 +83,7 @@ export class ManualsService {
|
||||
return { documents };
|
||||
}
|
||||
|
||||
async create(body: CreateManualDocumentDto) {
|
||||
async create(body: CreateManualDocumentDto, requester?: AdminRequester) {
|
||||
const document = await this.launcherPrisma.launcherManualDocument.create({
|
||||
data: {
|
||||
appKey: body.appKey.trim(),
|
||||
@@ -69,6 +91,7 @@ export class ManualsService {
|
||||
body: body.body.trim(),
|
||||
isPublished: body.isPublished ?? true,
|
||||
sortOrder: body.sortOrder ?? 0,
|
||||
...this.creatorData(requester),
|
||||
},
|
||||
});
|
||||
|
||||
@@ -105,6 +128,12 @@ export class ManualsService {
|
||||
|
||||
}
|
||||
|
||||
type AdminRequester = {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
};
|
||||
|
||||
function toPositiveInt(value: string | undefined, fallback: number) {
|
||||
const parsed = Number(value);
|
||||
return Number.isFinite(parsed) && parsed > 0 ? Math.floor(parsed) : fallback;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { AuthPrismaModule } from '../auth-prisma/auth-prisma.module';
|
||||
import { LauncherPrismaModule } from '../launcher-prisma/launcher-prisma.module';
|
||||
import { NoticesController } from './notices.controller';
|
||||
import { NoticesService } from './notices.service';
|
||||
|
||||
@Module({
|
||||
imports: [AuthPrismaModule, LauncherPrismaModule],
|
||||
imports: [LauncherPrismaModule],
|
||||
controllers: [NoticesController],
|
||||
providers: [NoticesService],
|
||||
})
|
||||
|
||||
@@ -2,9 +2,8 @@ import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
import { Prisma } from '@prisma/launcher-client';
|
||||
import { AuthPrismaService } from '../auth-prisma/auth-prisma.service';
|
||||
import { getAdminAvatarUrl } from '../admins/admin-avatar';
|
||||
import { LauncherPrismaService } from '../launcher-prisma/launcher-prisma.service';
|
||||
import { getUserAvatarUrl } from '../users/users.service';
|
||||
import {
|
||||
CreateLauncherNoticeDto,
|
||||
ListLauncherNoticesQuery,
|
||||
@@ -20,7 +19,6 @@ type AdminRequester = {
|
||||
@Injectable()
|
||||
export class NoticesService {
|
||||
constructor(
|
||||
private readonly authPrisma: AuthPrismaService,
|
||||
private readonly configService: ConfigService,
|
||||
private readonly launcherPrisma: LauncherPrismaService,
|
||||
) {}
|
||||
@@ -35,31 +33,11 @@ export class NoticesService {
|
||||
: {};
|
||||
}
|
||||
|
||||
private async withCreatorAvatars<T extends { createdByEmail?: string | null }>(items: T[]) {
|
||||
const emails = [...new Set(items.map((item) => item.createdByEmail).filter((email): email is string => Boolean(email)))];
|
||||
if (emails.length === 0) return items.map((item) => ({ ...item, createdByAvatarUrl: null }));
|
||||
|
||||
const users = await this.authPrisma.user.findMany({
|
||||
where: { email: { in: emails } },
|
||||
select: {
|
||||
id: true,
|
||||
email: true,
|
||||
profileImageMime: true,
|
||||
},
|
||||
});
|
||||
const userByEmail = new Map(users.map((user) => [user.email, user]));
|
||||
const authBaseUrl = this.configService.get<string>('AUTH_PUBLIC_URL')
|
||||
?? this.configService.get<string>('ATNMY_AUTH_URL')
|
||||
?? this.configService.get<string>('AUTH_EXTERNAL_URL')
|
||||
?? 'https://auth.autonomystudio.net';
|
||||
|
||||
return items.map((item) => {
|
||||
const user = item.createdByEmail ? userByEmail.get(item.createdByEmail) : null;
|
||||
return {
|
||||
...item,
|
||||
createdByAvatarUrl: getUserAvatarUrl(user?.id ?? '', user?.profileImageMime, authBaseUrl),
|
||||
};
|
||||
});
|
||||
private withCreatorAvatars<T extends { createdById?: string | null }>(items: T[]) {
|
||||
return items.map((item) => ({
|
||||
...item,
|
||||
createdByAvatarUrl: getAdminAvatarUrl(item.createdById, this.configService),
|
||||
}));
|
||||
}
|
||||
|
||||
async list(query: ListLauncherNoticesQuery) {
|
||||
|
||||
@@ -13,8 +13,11 @@ export class OrganizationsController {
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Body() body: CreateOrganizationDto) {
|
||||
return this.organizationsService.create(body);
|
||||
create(
|
||||
@Body() body: CreateOrganizationDto,
|
||||
@Req() request: { admin?: { id: string; name: string; email: string } },
|
||||
) {
|
||||
return this.organizationsService.create(body, request.admin);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
|
||||
@@ -1,12 +1,23 @@
|
||||
import { ConflictException, Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { Prisma } from '@prisma/auth-client';
|
||||
|
||||
import { getAdminAvatarUrl } from '../admins/admin-avatar';
|
||||
import { AuthPrismaService } from '../auth-prisma/auth-prisma.service';
|
||||
import { CreateOrganizationDto, ListOrganizationsQuery, UpdateOrganizationDto, UpdateOrganizationLicenseDto } from './dto';
|
||||
|
||||
type AdminRequester = {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
};
|
||||
|
||||
@Injectable()
|
||||
export class OrganizationsService {
|
||||
constructor(private readonly authPrisma: AuthPrismaService) {}
|
||||
constructor(
|
||||
private readonly authPrisma: AuthPrismaService,
|
||||
private readonly configService: ConfigService,
|
||||
) {}
|
||||
|
||||
async list(query: ListOrganizationsQuery = {}) {
|
||||
const page = toPositiveInt(query.page, 1);
|
||||
@@ -37,6 +48,9 @@ export class OrganizationsService {
|
||||
type: true,
|
||||
domain: true,
|
||||
defaultLicenseCode: true,
|
||||
createdById: true,
|
||||
createdByName: true,
|
||||
createdByEmail: true,
|
||||
createdAt: true,
|
||||
},
|
||||
}),
|
||||
@@ -51,6 +65,7 @@ export class OrganizationsService {
|
||||
organizations: organizations.map((organization, index) => ({
|
||||
...organization,
|
||||
defaultLicenseName: organization.defaultLicenseCode ? licenseNameByCode.get(organization.defaultLicenseCode) ?? organization.defaultLicenseCode : null,
|
||||
createdByAvatarUrl: getAdminAvatarUrl(organization.createdById, this.configService),
|
||||
no: total - ((page - 1) * limit + index),
|
||||
})),
|
||||
total,
|
||||
@@ -59,13 +74,20 @@ export class OrganizationsService {
|
||||
};
|
||||
}
|
||||
|
||||
async create(body: CreateOrganizationDto) {
|
||||
async create(body: CreateOrganizationDto, requester?: AdminRequester) {
|
||||
try {
|
||||
const organization = await this.authPrisma.organization.create({
|
||||
data: {
|
||||
name: body.name.trim(),
|
||||
type: body.type,
|
||||
domain: body.domain?.trim() || null,
|
||||
...(requester
|
||||
? {
|
||||
createdById: requester.id,
|
||||
createdByName: requester.name,
|
||||
createdByEmail: requester.email,
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
@@ -73,11 +95,19 @@ export class OrganizationsService {
|
||||
type: true,
|
||||
domain: true,
|
||||
defaultLicenseCode: true,
|
||||
createdById: true,
|
||||
createdByName: true,
|
||||
createdByEmail: true,
|
||||
createdAt: true,
|
||||
},
|
||||
});
|
||||
|
||||
return { organization };
|
||||
return {
|
||||
organization: {
|
||||
...organization,
|
||||
createdByAvatarUrl: getAdminAvatarUrl(organization.createdById, this.configService),
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof Prisma.PrismaClientKnownRequestError &&
|
||||
@@ -105,6 +135,9 @@ export class OrganizationsService {
|
||||
type: true,
|
||||
domain: true,
|
||||
defaultLicenseCode: true,
|
||||
createdById: true,
|
||||
createdByName: true,
|
||||
createdByEmail: true,
|
||||
createdAt: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { AuthPrismaModule } from '../auth-prisma/auth-prisma.module';
|
||||
import { LauncherPrismaModule } from '../launcher-prisma/launcher-prisma.module';
|
||||
import { TermsController } from './terms.controller';
|
||||
import { TermsService } from './terms.service';
|
||||
|
||||
@Module({
|
||||
imports: [AuthPrismaModule, LauncherPrismaModule],
|
||||
imports: [LauncherPrismaModule],
|
||||
controllers: [TermsController],
|
||||
providers: [TermsService],
|
||||
})
|
||||
|
||||
@@ -2,9 +2,8 @@ import { ConflictException, Injectable, NotFoundException } from '@nestjs/common
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
import { Prisma } from '@prisma/launcher-client';
|
||||
import { AuthPrismaService } from '../auth-prisma/auth-prisma.service';
|
||||
import { getAdminAvatarUrl } from '../admins/admin-avatar';
|
||||
import { LauncherPrismaService } from '../launcher-prisma/launcher-prisma.service';
|
||||
import { getUserAvatarUrl } from '../users/users.service';
|
||||
import { CreateTermDto, ListTermsQuery, UpdateTermDto } from './dto';
|
||||
|
||||
type AdminRequester = {
|
||||
@@ -16,7 +15,6 @@ type AdminRequester = {
|
||||
@Injectable()
|
||||
export class TermsService {
|
||||
constructor(
|
||||
private readonly authPrisma: AuthPrismaService,
|
||||
private readonly configService: ConfigService,
|
||||
private readonly launcherPrisma: LauncherPrismaService,
|
||||
) {}
|
||||
@@ -115,31 +113,11 @@ export class TermsService {
|
||||
: {};
|
||||
}
|
||||
|
||||
private async withCreatorAvatars<T extends { createdByEmail?: string | null }>(items: T[]) {
|
||||
const emails = [...new Set(items.map((item) => item.createdByEmail).filter((email): email is string => Boolean(email)))];
|
||||
if (emails.length === 0) return items.map((item) => ({ ...item, createdByAvatarUrl: null }));
|
||||
|
||||
const users = await this.authPrisma.user.findMany({
|
||||
where: { email: { in: emails } },
|
||||
select: {
|
||||
id: true,
|
||||
email: true,
|
||||
profileImageMime: true,
|
||||
},
|
||||
});
|
||||
const userByEmail = new Map(users.map((user) => [user.email, user]));
|
||||
const authBaseUrl = this.configService.get<string>('AUTH_PUBLIC_URL')
|
||||
?? this.configService.get<string>('ATNMY_AUTH_URL')
|
||||
?? this.configService.get<string>('AUTH_EXTERNAL_URL')
|
||||
?? 'https://auth.autonomystudio.net';
|
||||
|
||||
return items.map((item) => {
|
||||
const user = item.createdByEmail ? userByEmail.get(item.createdByEmail) : null;
|
||||
return {
|
||||
...item,
|
||||
createdByAvatarUrl: getUserAvatarUrl(user?.id ?? '', user?.profileImageMime, authBaseUrl),
|
||||
};
|
||||
});
|
||||
private withCreatorAvatars<T extends { createdById?: string | null }>(items: T[]) {
|
||||
return items.map((item) => ({
|
||||
...item,
|
||||
createdByAvatarUrl: getAdminAvatarUrl(item.createdById, this.configService),
|
||||
}));
|
||||
}
|
||||
|
||||
private async ensureExists(id: string) {
|
||||
|
||||
Reference in New Issue
Block a user