feat: add update and delete functionality for courses, events, and species; enhance attendance tracking and category creation
This commit is contained in:
@@ -33,19 +33,7 @@ export const createRecord = authActionClient
|
||||
}
|
||||
|
||||
// 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;
|
||||
const validation = validateRecordData(
|
||||
input.data as Record<string, unknown>,
|
||||
fields as Parameters<typeof validateRecordData>[1],
|
||||
@@ -98,19 +86,7 @@ export const updateRecord = authActionClient
|
||||
throw new Error('Module not found');
|
||||
}
|
||||
|
||||
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;
|
||||
const validation = validateRecordData(
|
||||
input.data as Record<string, unknown>,
|
||||
fields as Parameters<typeof validateRecordData>[1],
|
||||
|
||||
@@ -6,6 +6,7 @@ import type {
|
||||
CreateModuleInput,
|
||||
UpdateModuleInput,
|
||||
} from '../../schema/module.schema';
|
||||
import type { ModuleWithFields } from '../../types';
|
||||
|
||||
/**
|
||||
* Service for managing module definitions (CRUD).
|
||||
@@ -38,15 +39,20 @@ export function createModuleDefinitionService(
|
||||
return data;
|
||||
},
|
||||
|
||||
async getModuleWithFields(moduleId: string) {
|
||||
async getModuleWithFields(
|
||||
moduleId: string,
|
||||
): Promise<ModuleWithFields | null> {
|
||||
const { data, error } = await client
|
||||
.from('modules')
|
||||
.select('*, fields:module_fields(*)')
|
||||
.eq('id', moduleId)
|
||||
.single();
|
||||
|
||||
if (error) throw error;
|
||||
return data;
|
||||
if (error) {
|
||||
if (error.code === 'PGRST116') return null;
|
||||
throw error;
|
||||
}
|
||||
return data as unknown as ModuleWithFields;
|
||||
},
|
||||
|
||||
async createModule(input: CreateModuleInput) {
|
||||
|
||||
12
packages/features/module-builder/src/types.ts
Normal file
12
packages/features/module-builder/src/types.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import type { Tables } from '@kit/supabase/database';
|
||||
|
||||
/** A module row from the database */
|
||||
export type Module = Tables<'modules'>;
|
||||
|
||||
/** A module field row from the database */
|
||||
export type ModuleField = Tables<'module_fields'>;
|
||||
|
||||
/** Module with its field definitions joined */
|
||||
export interface ModuleWithFields extends Module {
|
||||
fields: ModuleField[];
|
||||
}
|
||||
Reference in New Issue
Block a user