Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+18
-8
@@ -10,6 +10,7 @@ import { createHash } from "node:crypto";
|
||||
import { CatalogError, foundationErrors } from "@hivegrid/foundation";
|
||||
import { createAuditEvent } from "@hivegrid/db/audit-events.server";
|
||||
import { withTenantRLS } from "~/utils/db/.server/tenantRls.server";
|
||||
import { requireValidHrAudienceWithTx } from "./hrAudience.server";
|
||||
import { HrServiceError } from "./hrService.server";
|
||||
|
||||
const HR_AUDIT_MODULE = "hr";
|
||||
@@ -50,11 +51,14 @@ export type CreateSurveyInput = { tenantId: string; authorUserId: string; title:
|
||||
export async function createSurvey(input: CreateSurveyInput): Promise<SurveyRow> {
|
||||
const title = input.title.trim();
|
||||
if (!title) throw new HrServiceError("hr.error.surveyTitleRequired");
|
||||
const created = (await withTenantRLS(input.tenantId, (tx) =>
|
||||
tx.hrSurvey.create({
|
||||
data: { tenantId: input.tenantId, authorUserId: input.authorUserId, title: title.slice(0, 255), description: input.description ?? null, isAnonymous: input.isAnonymous ?? false, resultVisibility: input.resultVisibility ?? "admins", audienceKind: input.audienceKind ?? "all", audienceRef: input.audienceRef ?? null, isDemoData: input.isDemoData ?? false },
|
||||
}),
|
||||
)) as SurveyRow;
|
||||
const audienceKind = input.audienceKind ?? "all";
|
||||
const audienceRef = audienceKind === "all" ? null : (input.audienceRef ?? null);
|
||||
const created = (await withTenantRLS(input.tenantId, async (tx) => {
|
||||
await requireValidHrAudienceWithTx(tx, { tenantId: input.tenantId, kind: audienceKind, ref: audienceRef });
|
||||
return tx.hrSurvey.create({
|
||||
data: { tenantId: input.tenantId, authorUserId: input.authorUserId, title: title.slice(0, 255), description: input.description ?? null, isAnonymous: input.isAnonymous ?? false, resultVisibility: input.resultVisibility ?? "admins", audienceKind, audienceRef, isDemoData: input.isDemoData ?? false },
|
||||
});
|
||||
})) as SurveyRow;
|
||||
await createAuditEvent({ tenantId: input.tenantId, actorId: input.authorUserId, actorType: "user", action: "HR_SURVEY_CREATE", targetType: "HrSurvey", targetId: created.id, sourceModule: HR_AUDIT_MODULE, outcome: "success" });
|
||||
return created;
|
||||
}
|
||||
@@ -63,8 +67,14 @@ export type UpdateSurveyInput = Partial<Omit<CreateSurveyInput, "tenantId" | "au
|
||||
|
||||
export async function updateSurvey(input: UpdateSurveyInput): Promise<void> {
|
||||
await withTenantRLS(input.tenantId, async (tx) => {
|
||||
const existing = await tx.hrSurvey.findFirst({ where: { id: input.surveyId, tenantId: input.tenantId }, select: { id: true } });
|
||||
const existing = await tx.hrSurvey.findFirst({
|
||||
where: { id: input.surveyId, tenantId: input.tenantId },
|
||||
select: { id: true, audienceKind: true, audienceRef: true },
|
||||
});
|
||||
if (!existing) throw new CatalogError(foundationErrors.notFound, { surveyId: input.surveyId });
|
||||
const audienceKind = input.audienceKind ?? existing.audienceKind;
|
||||
const audienceRef = audienceKind === "all" ? null : input.audienceRef !== undefined ? input.audienceRef : existing.audienceRef;
|
||||
await requireValidHrAudienceWithTx(tx, { tenantId: input.tenantId, kind: audienceKind, ref: audienceRef });
|
||||
await tx.hrSurvey.update({
|
||||
where: { id: input.surveyId },
|
||||
data: {
|
||||
@@ -72,8 +82,8 @@ export async function updateSurvey(input: UpdateSurveyInput): Promise<void> {
|
||||
...(input.description !== undefined ? { description: input.description } : {}),
|
||||
...(input.isAnonymous !== undefined ? { isAnonymous: input.isAnonymous } : {}),
|
||||
...(input.resultVisibility !== undefined ? { resultVisibility: input.resultVisibility } : {}),
|
||||
...(input.audienceKind !== undefined ? { audienceKind: input.audienceKind } : {}),
|
||||
...(input.audienceRef !== undefined ? { audienceRef: input.audienceRef } : {}),
|
||||
audienceKind,
|
||||
audienceRef,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user