sla show
This commit is contained in:
@@ -1576,7 +1576,7 @@ async function upsertDocumentSequencesForOrganizationV2(
|
||||
|
||||
async function upsertApprovalWorkflowsForOrganization(
|
||||
sql: SqlClient,
|
||||
organizationId: string,
|
||||
organization: { id: string; createdBy: string },
|
||||
) {
|
||||
for (const workflow of APPROVAL_WORKFLOWS) {
|
||||
const [workflowRow] = await sql`
|
||||
@@ -1587,14 +1587,18 @@ async function upsertApprovalWorkflowsForOrganization(
|
||||
name,
|
||||
entity_type,
|
||||
is_active,
|
||||
created_by,
|
||||
updated_by,
|
||||
deleted_at
|
||||
) values (
|
||||
${crypto.randomUUID()},
|
||||
${organizationId},
|
||||
${organization.id},
|
||||
${workflow.code},
|
||||
${workflow.name},
|
||||
${workflow.entityType},
|
||||
${true},
|
||||
${organization.createdBy},
|
||||
${organization.createdBy},
|
||||
${null}
|
||||
)
|
||||
on conflict (organization_id, code) do update
|
||||
@@ -1602,6 +1606,7 @@ async function upsertApprovalWorkflowsForOrganization(
|
||||
name = excluded.name,
|
||||
entity_type = excluded.entity_type,
|
||||
is_active = excluded.is_active,
|
||||
updated_by = excluded.updated_by,
|
||||
deleted_at = excluded.deleted_at,
|
||||
updated_at = now()
|
||||
returning id
|
||||
@@ -1620,7 +1625,7 @@ async function upsertApprovalWorkflowsForOrganization(
|
||||
deleted_at
|
||||
) values (
|
||||
${crypto.randomUUID()},
|
||||
${organizationId},
|
||||
${organization.id},
|
||||
${workflowRow.id},
|
||||
${step.stepNumber},
|
||||
${step.roleCode},
|
||||
@@ -2338,7 +2343,7 @@ async function main() {
|
||||
organization,
|
||||
branchRows,
|
||||
);
|
||||
await upsertApprovalWorkflowsForOrganization(sql, organization.id);
|
||||
await upsertApprovalWorkflowsForOrganization(sql, organization);
|
||||
await upsertApprovalMatricesForOrganization(sql, organization);
|
||||
await upsertDocumentTemplatesForOrganization(sql, organization);
|
||||
await upsertDocumentLibraryForOrganization(sql, organization);
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { getDefaultPermissions } from '../../lib/auth/rbac.ts';
|
||||
import { createSqlClient, deterministicId, type SqlClient } from '../../../scripts/lib/seed-utils.ts';
|
||||
import { getDefaultPermissions } from "../../lib/auth/rbac.ts";
|
||||
import {
|
||||
createSqlClient,
|
||||
deterministicId,
|
||||
type SqlClient,
|
||||
} from "../../../scripts/lib/seed-utils.ts";
|
||||
|
||||
type UserRow = {
|
||||
id: string;
|
||||
@@ -7,17 +11,19 @@ type UserRow = {
|
||||
};
|
||||
|
||||
const DEFAULT_ORGANIZATION = {
|
||||
id: deterministicId('organization:alla-demo'),
|
||||
name: 'ALLA Demo Organization',
|
||||
slug: 'alla-demo',
|
||||
membershipId: deterministicId('membership:alla-demo:super-admin')
|
||||
id: deterministicId("organization:alla-demo"),
|
||||
name: "ALLA Demo",
|
||||
slug: "alla-demo",
|
||||
membershipId: deterministicId("membership:alla-demo:super-admin"),
|
||||
};
|
||||
|
||||
async function resolveSuperAdmin(sql: SqlClient): Promise<UserRow> {
|
||||
const email = process.env.SUPER_ADMIN_EMAIL?.trim().toLowerCase();
|
||||
|
||||
if (!email) {
|
||||
throw new Error('SUPER_ADMIN_EMAIL is required before running system organization seed.');
|
||||
throw new Error(
|
||||
"SUPER_ADMIN_EMAIL is required before running system organization seed.",
|
||||
);
|
||||
}
|
||||
|
||||
const [user] = await sql<UserRow[]>`
|
||||
@@ -28,7 +34,7 @@ async function resolveSuperAdmin(sql: SqlClient): Promise<UserRow> {
|
||||
`;
|
||||
|
||||
if (!user) {
|
||||
throw new Error('Super admin user not found. Run seed-super-admin first.');
|
||||
throw new Error("Super admin user not found. Run seed-super-admin first.");
|
||||
}
|
||||
|
||||
return user;
|
||||
@@ -46,7 +52,7 @@ async function ensureOrganization(sql: SqlClient, superAdmin: UserRow) {
|
||||
${DEFAULT_ORGANIZATION.id},
|
||||
${DEFAULT_ORGANIZATION.name},
|
||||
${DEFAULT_ORGANIZATION.slug},
|
||||
${'enterprise'},
|
||||
${"enterprise"},
|
||||
${superAdmin.id}
|
||||
)
|
||||
on conflict (slug) do update
|
||||
@@ -56,7 +62,7 @@ async function ensureOrganization(sql: SqlClient, superAdmin: UserRow) {
|
||||
updated_at = now()
|
||||
`;
|
||||
|
||||
const membershipPermissions = getDefaultPermissions('admin', 'crm_admin');
|
||||
const membershipPermissions = getDefaultPermissions("admin", "crm_admin");
|
||||
const [existingMembership] = await sql<{ id: string }[]>`
|
||||
select id
|
||||
from memberships
|
||||
@@ -69,8 +75,8 @@ async function ensureOrganization(sql: SqlClient, superAdmin: UserRow) {
|
||||
await sql`
|
||||
update memberships
|
||||
set
|
||||
role = ${'admin'},
|
||||
business_role = ${'crm_admin'},
|
||||
role = ${"admin"},
|
||||
business_role = ${"crm_admin"},
|
||||
permissions = ${sql.array(membershipPermissions)},
|
||||
updated_at = now()
|
||||
where id = ${existingMembership.id}
|
||||
@@ -90,8 +96,8 @@ async function ensureOrganization(sql: SqlClient, superAdmin: UserRow) {
|
||||
${DEFAULT_ORGANIZATION.membershipId},
|
||||
${superAdmin.id},
|
||||
${DEFAULT_ORGANIZATION.id},
|
||||
${'admin'},
|
||||
${'crm_admin'},
|
||||
${"admin"},
|
||||
${"crm_admin"},
|
||||
${sql.array(membershipPermissions)},
|
||||
${sql.array([])},
|
||||
${sql.array([])}
|
||||
@@ -122,8 +128,8 @@ async function main() {
|
||||
|
||||
main().catch((error) => {
|
||||
console.error(
|
||||
'[seed:system-org] Failed:',
|
||||
error instanceof Error ? error.message : String(error)
|
||||
"[seed:system-org] Failed:",
|
||||
error instanceof Error ? error.message : String(error),
|
||||
);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
|
||||
@@ -1,36 +1,38 @@
|
||||
export const DOCUMENT_LIBRARY_TYPES = [
|
||||
'sla',
|
||||
'warranty',
|
||||
'terms_conditions',
|
||||
'company_profile',
|
||||
'datasheet',
|
||||
'drawing',
|
||||
'certificate',
|
||||
'appendix',
|
||||
'safety_document',
|
||||
'installation_manual'
|
||||
"sla",
|
||||
"warranty",
|
||||
"terms_conditions",
|
||||
"company_profile",
|
||||
"datasheet",
|
||||
"drawing",
|
||||
"certificate",
|
||||
"appendix",
|
||||
"safety_document",
|
||||
"installation_manual",
|
||||
] as const;
|
||||
|
||||
export const DOCUMENT_LIBRARY_BRANDS = ['alla', 'onvalla', 'generic'] as const;
|
||||
export const DOCUMENT_LIBRARY_LANGUAGES = ['th', 'en'] as const;
|
||||
export const DOCUMENT_LIBRARY_BRANDS = ["alla", "onvalla", "generic"] as const;
|
||||
export const DOCUMENT_LIBRARY_LANGUAGES = ["th", "en"] as const;
|
||||
export const DOCUMENT_LIBRARY_PRODUCT_TYPES = [
|
||||
'all',
|
||||
'crane',
|
||||
'dock_door',
|
||||
'solar',
|
||||
'service'
|
||||
"all",
|
||||
"crane",
|
||||
"dock_door",
|
||||
"solar",
|
||||
"service",
|
||||
] as const;
|
||||
export const DOCUMENT_LIBRARY_VERSION_STATUSES = [
|
||||
'draft',
|
||||
'published',
|
||||
'active',
|
||||
'archived'
|
||||
"draft",
|
||||
"published",
|
||||
"active",
|
||||
"archived",
|
||||
] as const;
|
||||
|
||||
export type DocumentLibraryType = (typeof DOCUMENT_LIBRARY_TYPES)[number];
|
||||
export type DocumentLibraryBrand = (typeof DOCUMENT_LIBRARY_BRANDS)[number];
|
||||
export type DocumentLibraryLanguage = (typeof DOCUMENT_LIBRARY_LANGUAGES)[number];
|
||||
export type DocumentLibraryProductType = (typeof DOCUMENT_LIBRARY_PRODUCT_TYPES)[number];
|
||||
export type DocumentLibraryLanguage =
|
||||
(typeof DOCUMENT_LIBRARY_LANGUAGES)[number];
|
||||
export type DocumentLibraryProductType =
|
||||
(typeof DOCUMENT_LIBRARY_PRODUCT_TYPES)[number];
|
||||
export type DocumentLibraryVersionStatus =
|
||||
(typeof DOCUMENT_LIBRARY_VERSION_STATUSES)[number];
|
||||
|
||||
@@ -44,7 +46,7 @@ export interface DocumentLibraryRecord {
|
||||
brand: DocumentLibraryBrand;
|
||||
language: DocumentLibraryLanguage;
|
||||
productType: DocumentLibraryProductType;
|
||||
status: 'active' | 'inactive';
|
||||
status: "active" | "inactive";
|
||||
isActive: boolean;
|
||||
createdBy: string;
|
||||
updatedBy: string;
|
||||
@@ -91,7 +93,7 @@ export interface DocumentLibraryFilters {
|
||||
brand?: DocumentLibraryBrand;
|
||||
language?: DocumentLibraryLanguage;
|
||||
productType?: DocumentLibraryProductType;
|
||||
isActive?: 'true' | 'false';
|
||||
isActive?: "true" | "false";
|
||||
}
|
||||
|
||||
export interface DocumentLibraryMutationPayload {
|
||||
|
||||
Reference in New Issue
Block a user