Add account hierarchy framework with migrations, RLS policies, and UI components
This commit is contained in:
@@ -4,7 +4,10 @@ import { authActionClient } from '@kit/next/safe-action';
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
import { CreateModuleSchema, UpdateModuleSchema } from '../../schema/module.schema';
|
||||
import {
|
||||
CreateModuleSchema,
|
||||
UpdateModuleSchema,
|
||||
} from '../../schema/module.schema';
|
||||
import { createModuleBuilderApi } from '../api';
|
||||
|
||||
export const createModule = authActionClient
|
||||
@@ -14,11 +17,17 @@ export const createModule = authActionClient
|
||||
const logger = await getLogger();
|
||||
const api = createModuleBuilderApi(client);
|
||||
|
||||
logger.info({ name: 'modules.create', moduleName: input.name }, 'Creating module...');
|
||||
logger.info(
|
||||
{ name: 'modules.create', moduleName: input.name },
|
||||
'Creating module...',
|
||||
);
|
||||
|
||||
const module = await api.modules.createModule(input);
|
||||
|
||||
logger.info({ name: 'modules.create', moduleId: module.id }, 'Module created');
|
||||
logger.info(
|
||||
{ name: 'modules.create', moduleId: module.id },
|
||||
'Module created',
|
||||
);
|
||||
|
||||
return { success: true, module };
|
||||
});
|
||||
@@ -30,11 +39,17 @@ export const updateModule = authActionClient
|
||||
const logger = await getLogger();
|
||||
const api = createModuleBuilderApi(client);
|
||||
|
||||
logger.info({ name: 'modules.update', moduleId: input.moduleId }, 'Updating module...');
|
||||
logger.info(
|
||||
{ name: 'modules.update', moduleId: input.moduleId },
|
||||
'Updating module...',
|
||||
);
|
||||
|
||||
const module = await api.modules.updateModule(input);
|
||||
|
||||
logger.info({ name: 'modules.update', moduleId: module.id }, 'Module updated');
|
||||
logger.info(
|
||||
{ name: 'modules.update', moduleId: module.id },
|
||||
'Module updated',
|
||||
);
|
||||
|
||||
return { success: true, module };
|
||||
});
|
||||
|
||||
@@ -6,7 +6,12 @@ import { authActionClient } from '@kit/next/safe-action';
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
import { CreateRecordSchema, UpdateRecordSchema, DeleteRecordSchema, LockRecordSchema } from '../../schema/module-record.schema';
|
||||
import {
|
||||
CreateRecordSchema,
|
||||
UpdateRecordSchema,
|
||||
DeleteRecordSchema,
|
||||
LockRecordSchema,
|
||||
} from '../../schema/module-record.schema';
|
||||
import { createModuleBuilderApi } from '../api';
|
||||
import { validateRecordData } from '../services/record-validation.service';
|
||||
|
||||
@@ -19,14 +24,28 @@ export const createRecord = authActionClient
|
||||
const userId = ctx.user.id;
|
||||
|
||||
// Get field definitions for validation
|
||||
const moduleWithFields = await api.modules.getModuleWithFields(input.moduleId);
|
||||
const moduleWithFields = await api.modules.getModuleWithFields(
|
||||
input.moduleId,
|
||||
);
|
||||
|
||||
if (!moduleWithFields) {
|
||||
throw new Error('Module not found');
|
||||
}
|
||||
|
||||
// Validate data against field definitions
|
||||
const fields = (moduleWithFields as unknown as { fields: Array<{ name: string; field_type: string; is_required: boolean; min_value?: number | null; max_value?: number | null; max_length?: number | null; regex_pattern?: string | null }> }).fields;
|
||||
const fields = (
|
||||
moduleWithFields as unknown as {
|
||||
fields: Array<{
|
||||
name: string;
|
||||
field_type: string;
|
||||
is_required: boolean;
|
||||
min_value?: number | null;
|
||||
max_value?: number | null;
|
||||
max_length?: number | null;
|
||||
regex_pattern?: string | null;
|
||||
}>;
|
||||
}
|
||||
).fields;
|
||||
const validation = validateRecordData(
|
||||
input.data as Record<string, unknown>,
|
||||
fields as Parameters<typeof validateRecordData>[1],
|
||||
@@ -36,7 +55,10 @@ export const createRecord = authActionClient
|
||||
return { success: false, errors: validation.errors };
|
||||
}
|
||||
|
||||
logger.info({ name: 'records.create', moduleId: input.moduleId }, 'Creating record...');
|
||||
logger.info(
|
||||
{ name: 'records.create', moduleId: input.moduleId },
|
||||
'Creating record...',
|
||||
);
|
||||
|
||||
const record = await api.records.createRecord(input, userId);
|
||||
|
||||
@@ -64,7 +86,10 @@ export const updateRecord = authActionClient
|
||||
// Get existing record for audit
|
||||
const existing = await api.records.getRecord(input.recordId);
|
||||
|
||||
logger.info({ name: 'records.update', recordId: input.recordId }, 'Updating record...');
|
||||
logger.info(
|
||||
{ name: 'records.update', recordId: input.recordId },
|
||||
'Updating record...',
|
||||
);
|
||||
|
||||
const record = await api.records.updateRecord(input, userId);
|
||||
|
||||
@@ -93,7 +118,10 @@ export const deleteRecord = authActionClient
|
||||
// Get existing record for audit
|
||||
const existing = await api.records.getRecord(input.recordId);
|
||||
|
||||
logger.info({ name: 'records.delete', recordId: input.recordId, hard: input.hard }, 'Deleting record...');
|
||||
logger.info(
|
||||
{ name: 'records.delete', recordId: input.recordId, hard: input.hard },
|
||||
'Deleting record...',
|
||||
);
|
||||
|
||||
await api.records.deleteRecord(input);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user