feat: complete UI/UX improvements, vuesax icons, media server, and section management

This commit is contained in:
s.esmaeili
2026-10-23 21:06:15 +03:30
parent 49f30a96b1
commit fa61a76444
64 changed files with 4527 additions and 819 deletions
+79
View File
@@ -8,6 +8,7 @@ import {
Module,
NotFoundException,
Param,
Patch,
Put,
ServiceUnavailableException,
} from "@nestjs/common";
@@ -75,6 +76,68 @@ export class SectionsService {
this.revalidate.trigger();
return { key, data: parsed.data, updatedAt: row.updatedAt };
}
async listAdmin() {
const rows = await this.prisma.siteSection.findMany();
const byKey = new Map(rows.map((r) => [r.key, r]));
return SECTION_KEYS.map((key) => {
const row = byKey.get(key);
let data: any = null;
if (row) {
const parsed = sectionSchemas[key].safeParse(row.data);
data = parsed.success ? parsed.data : row.data;
}
return {
key,
updatedAt: row?.updatedAt?.toISOString() ?? null,
enabled:
data && typeof data === "object" && "enabled" in data
? (data.enabled as boolean) !== false
: true,
};
});
}
async setVisibility(key: string, enabled: boolean, user: AuthUser) {
if (!isSectionKey(key)) throw new NotFoundException("بخش پیدا نشد");
if (key === "settings") {
throw new BadRequestException("تنظیمات سایت قابلیت تغییر وضعیت نمایش ندارد");
}
const row = await this.prisma.siteSection.findUnique({ where: { key } });
if (!row) throw new NotFoundException("بخش پیدا نشد");
const currentData =
row.data && typeof row.data === "object" ? { ...(row.data as object) } : {};
(currentData as Record<string, unknown>).enabled = enabled;
const parsed = sectionSchemas[key].safeParse(currentData);
if (!parsed.success) {
throw new BadRequestException({
statusCode: 400,
message: "اطلاعات بخش معتبر نیست",
issues: toIssues(parsed.error),
});
}
const updated = await this.prisma.siteSection.update({
where: { key },
data: { data: parsed.data, updatedById: user.id },
});
this.audit.log(
user.id,
"update",
"section",
key,
`تغییر وضعیت نمایش به ${enabled ? "نمایش" : "عدم نمایش"}`,
);
this.revalidate.trigger();
return {
key,
enabled: ((parsed.data as any).enabled as boolean) !== false,
updatedAt: updated.updatedAt.toISOString(),
};
}
}
@AdminAuth()
@@ -82,6 +145,11 @@ export class SectionsService {
export class SectionsController {
constructor(private readonly sections: SectionsService) {}
@Get()
list() {
return this.sections.listAdmin();
}
@Get(":key")
get(@Param("key") key: string) {
return this.sections.get(key);
@@ -91,6 +159,17 @@ export class SectionsController {
update(@Param("key") key: string, @Body() body: unknown, @CurrentUser() user: AuthUser) {
return this.sections.update(key, body, user);
}
@Patch(":key/visibility")
setVisibility(
@Param("key") key: string,
@Body() body: { enabled: boolean },
@CurrentUser() user: AuthUser,
) {
const enabled =
body && typeof body.enabled === "boolean" ? body.enabled : Boolean(body?.enabled);
return this.sections.setVisibility(key, enabled, user);
}
}
@Module({