refactor: remove obsolete member management API module
This commit is contained in:
@@ -6,6 +6,7 @@ import { authActionClient } from '@kit/next/safe-action';
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
import { isCourseDomainError } from '../../lib/errors';
|
||||
import {
|
||||
CreateCourseSchema,
|
||||
UpdateCourseSchema,
|
||||
@@ -25,7 +26,7 @@ export const createCourse = authActionClient
|
||||
const api = createCourseManagementApi(client);
|
||||
|
||||
logger.info({ name: 'course.create' }, 'Creating course...');
|
||||
const result = await api.createCourse(input);
|
||||
const result = await api.courses.create(input, ctx.user.id);
|
||||
logger.info({ name: 'course.create' }, 'Course created');
|
||||
return { success: true, data: result };
|
||||
});
|
||||
@@ -37,39 +38,60 @@ export const updateCourse = authActionClient
|
||||
const logger = await getLogger();
|
||||
const api = createCourseManagementApi(client);
|
||||
|
||||
logger.info({ name: 'course.update' }, 'Updating course...');
|
||||
const result = await api.updateCourse(input);
|
||||
logger.info({ name: 'course.update' }, 'Course updated');
|
||||
return { success: true, data: result };
|
||||
try {
|
||||
logger.info({ name: 'course.update' }, 'Updating course...');
|
||||
const result = await api.courses.update(input, ctx.user.id);
|
||||
logger.info({ name: 'course.update' }, 'Course updated');
|
||||
return { success: true, data: result };
|
||||
} catch (e) {
|
||||
if (isCourseDomainError(e)) {
|
||||
return { success: false, error: e.message, code: e.code };
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
export const deleteCourse = authActionClient
|
||||
.inputSchema(z.object({ courseId: z.string().uuid() }))
|
||||
.action(async ({ parsedInput: input, ctx }) => {
|
||||
.action(async ({ parsedInput: input, ctx: _ctx }) => {
|
||||
const client = getSupabaseServerClient();
|
||||
const logger = await getLogger();
|
||||
const api = createCourseManagementApi(client);
|
||||
|
||||
logger.info({ name: 'course.delete' }, 'Archiving course...');
|
||||
await api.deleteCourse(input.courseId);
|
||||
logger.info({ name: 'course.delete' }, 'Course archived');
|
||||
return { success: true };
|
||||
try {
|
||||
logger.info({ name: 'course.delete' }, 'Archiving course...');
|
||||
await api.courses.softDelete(input.courseId);
|
||||
logger.info({ name: 'course.delete' }, 'Course archived');
|
||||
return { success: true };
|
||||
} catch (e) {
|
||||
if (isCourseDomainError(e)) {
|
||||
return { success: false, error: e.message, code: e.code };
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
export const enrollParticipant = authActionClient
|
||||
.inputSchema(EnrollParticipantSchema)
|
||||
.action(async ({ parsedInput: input, ctx }) => {
|
||||
.action(async ({ parsedInput: input, ctx: _ctx }) => {
|
||||
const client = getSupabaseServerClient();
|
||||
const logger = await getLogger();
|
||||
const api = createCourseManagementApi(client);
|
||||
|
||||
logger.info(
|
||||
{ name: 'course.enrollParticipant' },
|
||||
'Enrolling participant...',
|
||||
);
|
||||
const result = await api.enrollParticipant(input);
|
||||
logger.info({ name: 'course.enrollParticipant' }, 'Participant enrolled');
|
||||
return { success: true, data: result };
|
||||
try {
|
||||
logger.info(
|
||||
{ name: 'course.enrollParticipant' },
|
||||
'Enrolling participant...',
|
||||
);
|
||||
const result = await api.enrollment.enroll(input);
|
||||
logger.info({ name: 'course.enrollParticipant' }, 'Participant enrolled');
|
||||
return { success: true, data: result };
|
||||
} catch (e) {
|
||||
if (isCourseDomainError(e)) {
|
||||
return { success: false, error: e.message, code: e.code };
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
export const cancelEnrollment = authActionClient
|
||||
@@ -78,7 +100,7 @@ export const cancelEnrollment = authActionClient
|
||||
participantId: z.string().uuid(),
|
||||
}),
|
||||
)
|
||||
.action(async ({ parsedInput: input, ctx }) => {
|
||||
.action(async ({ parsedInput: input, ctx: _ctx }) => {
|
||||
const client = getSupabaseServerClient();
|
||||
const logger = await getLogger();
|
||||
const api = createCourseManagementApi(client);
|
||||
@@ -87,9 +109,9 @@ export const cancelEnrollment = authActionClient
|
||||
{ name: 'course.cancelEnrollment' },
|
||||
'Cancelling enrollment...',
|
||||
);
|
||||
const result = await api.cancelEnrollment(input.participantId);
|
||||
await api.enrollment.cancel(input.participantId);
|
||||
logger.info({ name: 'course.cancelEnrollment' }, 'Enrollment cancelled');
|
||||
return { success: true, data: result };
|
||||
return { success: true };
|
||||
});
|
||||
|
||||
export const markAttendance = authActionClient
|
||||
@@ -100,69 +122,69 @@ export const markAttendance = authActionClient
|
||||
present: z.boolean(),
|
||||
}),
|
||||
)
|
||||
.action(async ({ parsedInput: input, ctx }) => {
|
||||
.action(async ({ parsedInput: input, ctx: _ctx }) => {
|
||||
const client = getSupabaseServerClient();
|
||||
const logger = await getLogger();
|
||||
const api = createCourseManagementApi(client);
|
||||
|
||||
logger.info({ name: 'course.markAttendance' }, 'Marking attendance...');
|
||||
const result = await api.markAttendance(
|
||||
await api.attendance.mark(
|
||||
input.sessionId,
|
||||
input.participantId,
|
||||
input.present,
|
||||
);
|
||||
logger.info({ name: 'course.markAttendance' }, 'Attendance marked');
|
||||
return { success: true, data: result };
|
||||
return { success: true };
|
||||
});
|
||||
|
||||
export const createCategory = authActionClient
|
||||
.inputSchema(CreateCategorySchema)
|
||||
.action(async ({ parsedInput: input, ctx }) => {
|
||||
.action(async ({ parsedInput: input, ctx: _ctx }) => {
|
||||
const client = getSupabaseServerClient();
|
||||
const logger = await getLogger();
|
||||
const api = createCourseManagementApi(client);
|
||||
|
||||
logger.info({ name: 'course.createCategory' }, 'Creating category...');
|
||||
const result = await api.createCategory(input);
|
||||
const result = await api.referenceData.createCategory(input);
|
||||
logger.info({ name: 'course.createCategory' }, 'Category created');
|
||||
return { success: true, data: result };
|
||||
});
|
||||
|
||||
export const createInstructor = authActionClient
|
||||
.inputSchema(CreateInstructorSchema)
|
||||
.action(async ({ parsedInput: input, ctx }) => {
|
||||
.action(async ({ parsedInput: input, ctx: _ctx }) => {
|
||||
const client = getSupabaseServerClient();
|
||||
const logger = await getLogger();
|
||||
const api = createCourseManagementApi(client);
|
||||
|
||||
logger.info({ name: 'course.createInstructor' }, 'Creating instructor...');
|
||||
const result = await api.createInstructor(input);
|
||||
const result = await api.referenceData.createInstructor(input);
|
||||
logger.info({ name: 'course.createInstructor' }, 'Instructor created');
|
||||
return { success: true, data: result };
|
||||
});
|
||||
|
||||
export const createLocation = authActionClient
|
||||
.inputSchema(CreateLocationSchema)
|
||||
.action(async ({ parsedInput: input, ctx }) => {
|
||||
.action(async ({ parsedInput: input, ctx: _ctx }) => {
|
||||
const client = getSupabaseServerClient();
|
||||
const logger = await getLogger();
|
||||
const api = createCourseManagementApi(client);
|
||||
|
||||
logger.info({ name: 'course.createLocation' }, 'Creating location...');
|
||||
const result = await api.createLocation(input);
|
||||
const result = await api.referenceData.createLocation(input);
|
||||
logger.info({ name: 'course.createLocation' }, 'Location created');
|
||||
return { success: true, data: result };
|
||||
});
|
||||
|
||||
export const createSession = authActionClient
|
||||
.inputSchema(CreateSessionSchema)
|
||||
.action(async ({ parsedInput: input, ctx }) => {
|
||||
.action(async ({ parsedInput: input, ctx: _ctx }) => {
|
||||
const client = getSupabaseServerClient();
|
||||
const logger = await getLogger();
|
||||
const api = createCourseManagementApi(client);
|
||||
|
||||
logger.info({ name: 'course.createSession' }, 'Creating session...');
|
||||
const result = await api.createSession(input);
|
||||
const result = await api.sessions.create(input);
|
||||
logger.info({ name: 'course.createSession' }, 'Session created');
|
||||
return { success: true, data: result };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user