Skip to content

Commit

Permalink
Revert #120 "Add milestone age groups"
Browse files Browse the repository at this point in the history
- resolves #131
  • Loading branch information
lkeegan committed Oct 25, 2024
1 parent 5fac037 commit b94ab08
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 601 deletions.
82 changes: 9 additions & 73 deletions frontend/src/lib/admin.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@ import {
authCookieLogin,
getMilestoneGroupsAdmin,
getUserQuestionsAdmin,
getMilestoneAgeGroups,
createMilestoneAgeGroup,
deleteMilestoneAgeGroup,
usersCurrentUser,
updateMilestoneAgeGroup
usersCurrentUser
} from '$lib/client/services.gen';
import type {
MilestoneAgeGroupPublic,
GetLanguagesResponse,
MilestoneGroupAdmin,
MilestoneAgeGroupCreate,
UserQuestionAdmin,
UserRead,
Body_auth_cookie_login_auth_login_post
} from '$lib/client/types.gen';
Expand Down Expand Up @@ -51,24 +47,12 @@ export const adminUser = AdminUser();

export async function refreshMilestoneGroups() {
console.log('refreshMilestoneGroups...');
await milestoneAgeGroups.refresh();
if (!milestoneAgeGroups.value) {
return;
}
const groups = {} as Record<string, Array<MilestoneGroupAdmin>>;
for (const ageGroup of milestoneAgeGroups.value) {
const { data, error } = await getMilestoneGroupsAdmin({
query: {
milestone_age_group_id: ageGroup.id
}
});
if (error || data == undefined) {
console.log(`Failed to get MilestoneGroups for ${ageGroup}`);
} else {
groups[`${ageGroup.id}`] = data;
}
milestoneGroups.set(groups);
console.log(groups);
const { data, error } = await getMilestoneGroupsAdmin();
if (error || data == undefined) {
console.log('Failed to get MilestoneGroups');
milestoneGroups.set([]);
} else {
milestoneGroups.set(data);
}
}

Expand All @@ -86,51 +70,3 @@ export async function refreshUserQuestions() {
userQuestions.set(data);
}
}

function MilestoneAgeGroups() {
let milestoneAgeGroups = $state(null as Array<MilestoneAgeGroupPublic> | null);
return {
get value(): Array<MilestoneAgeGroupPublic> | null {
return milestoneAgeGroups;
},
create: async function (ageGroup: MilestoneAgeGroupCreate) {
const { data, error } = await createMilestoneAgeGroup({ body: ageGroup });
if (error || data === undefined) {
console.log(`Failed to create MilestoneAgeGroup ${ageGroup}`);
} else {
await this.refresh();
}
},
save: async function (ageGroup: MilestoneAgeGroupPublic) {
const { data, error } = await updateMilestoneAgeGroup({ body: ageGroup });
if (error || data === undefined) {
console.log(`Failed to save MilestoneAgeGroup ${ageGroup}`);
} else {
await this.refresh();
}
},
delete: async function (id: number) {
const { data, error } = await deleteMilestoneAgeGroup({
path: {
milestone_age_group_id: id
}
});
if (error || data === undefined) {
console.log(`Failed to delete MilestoneAgeGroup ${id}`);
} else {
await this.refresh();
}
},
refresh: async function () {
const { data, error } = await getMilestoneAgeGroups();
if (error || data === undefined) {
console.log('Failed to get MilestoneAgeGroups');
milestoneAgeGroups = null;
} else {
milestoneAgeGroups = data;
}
}
};
}

export const milestoneAgeGroups = MilestoneAgeGroups();
52 changes: 2 additions & 50 deletions frontend/src/lib/client/schemas.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,42 +284,6 @@ export const MilestoneAdminSchema = {
title: 'MilestoneAdmin'
} as const;

export const MilestoneAgeGroupCreateSchema = {
properties: {
months_min: {
type: 'integer',
title: 'Months Min'
},
months_max: {
type: 'integer',
title: 'Months Max'
}
},
type: 'object',
required: ['months_min', 'months_max'],
title: 'MilestoneAgeGroupCreate'
} as const;

export const MilestoneAgeGroupPublicSchema = {
properties: {
months_min: {
type: 'integer',
title: 'Months Min'
},
months_max: {
type: 'integer',
title: 'Months Max'
},
id: {
type: 'integer',
title: 'Id'
}
},
type: 'object',
required: ['months_min', 'months_max', 'id'],
title: 'MilestoneAgeGroupPublic'
} as const;

export const MilestoneAnswerPublicSchema = {
properties: {
milestone_id: {
Expand All @@ -342,14 +306,6 @@ export const MilestoneAnswerSessionPublicSchema = {
type: 'integer',
title: 'Id'
},
child_id: {
type: 'integer',
title: 'Child Id'
},
age_group_id: {
type: 'integer',
title: 'Age Group Id'
},
created_at: {
type: 'string',
format: 'date-time',
Expand All @@ -364,7 +320,7 @@ export const MilestoneAnswerSessionPublicSchema = {
}
},
type: 'object',
required: ['id', 'child_id', 'age_group_id', 'created_at', 'answers'],
required: ['id', 'created_at', 'answers'],
title: 'MilestoneAnswerSessionPublic'
} as const;

Expand All @@ -374,10 +330,6 @@ export const MilestoneGroupAdminSchema = {
type: 'integer',
title: 'Id'
},
age_group_id: {
type: 'integer',
title: 'Age Group Id'
},
order: {
type: 'integer',
title: 'Order'
Expand All @@ -400,7 +352,7 @@ export const MilestoneGroupAdminSchema = {
}
},
type: 'object',
required: ['id', 'age_group_id', 'order'],
required: ['id', 'order'],
title: 'MilestoneGroupAdmin'
} as const;

Expand Down
86 changes: 4 additions & 82 deletions frontend/src/lib/client/services.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ import type {
GetMilestoneData,
GetMilestoneError,
GetMilestoneResponse,
GetMilestoneGroupsData,
GetMilestoneGroupsError,
GetMilestoneGroupsResponse,
GetMilestoneGroupData,
GetMilestoneGroupError,
GetMilestoneGroupResponse,
GetMilestoneAgeGroupsError,
GetMilestoneAgeGroupsResponse,
GetUserQuestionsError,
GetUserQuestionsResponse,
CreateLanguageData,
Expand All @@ -34,19 +31,8 @@ import type {
UpdateI18NData,
UpdateI18NError,
UpdateI18NResponse,
UpdateMilestoneAgeGroupData,
UpdateMilestoneAgeGroupError,
UpdateMilestoneAgeGroupResponse,
CreateMilestoneAgeGroupData,
CreateMilestoneAgeGroupError,
CreateMilestoneAgeGroupResponse,
DeleteMilestoneAgeGroupData,
DeleteMilestoneAgeGroupError,
DeleteMilestoneAgeGroupResponse,
GetMilestoneGroupsAdminData,
GetMilestoneGroupsAdminError,
GetMilestoneGroupsAdminResponse,
CreateMilestoneGroupAdminData,
CreateMilestoneGroupAdminError,
CreateMilestoneGroupAdminResponse,
UpdateMilestoneGroupAdminData,
Expand Down Expand Up @@ -188,7 +174,7 @@ export const getMilestone = <ThrowOnError extends boolean = false>(
* Get Milestone Groups
*/
export const getMilestoneGroups = <ThrowOnError extends boolean = false>(
options: Options<GetMilestoneGroupsData, ThrowOnError>
options?: Options<unknown, ThrowOnError>
) => {
return (options?.client ?? client).get<
GetMilestoneGroupsResponse,
Expand Down Expand Up @@ -216,22 +202,6 @@ export const getMilestoneGroup = <ThrowOnError extends boolean = false>(
});
};

/**
* Get Milestone Age Groups
*/
export const getMilestoneAgeGroups = <ThrowOnError extends boolean = false>(
options?: Options<unknown, ThrowOnError>
) => {
return (options?.client ?? client).get<
GetMilestoneAgeGroupsResponse,
GetMilestoneAgeGroupsError,
ThrowOnError
>({
...options,
url: '/milestone-age-groups/'
});
};

/**
* Get User Questions
*/
Expand Down Expand Up @@ -292,59 +262,11 @@ export const updateI18N = <ThrowOnError extends boolean = false>(
});
};

/**
* Update Milestone Age Group
*/
export const updateMilestoneAgeGroup = <ThrowOnError extends boolean = false>(
options: Options<UpdateMilestoneAgeGroupData, ThrowOnError>
) => {
return (options?.client ?? client).put<
UpdateMilestoneAgeGroupResponse,
UpdateMilestoneAgeGroupError,
ThrowOnError
>({
...options,
url: '/admin/milestone-age-groups/'
});
};

/**
* Create Milestone Age Group
*/
export const createMilestoneAgeGroup = <ThrowOnError extends boolean = false>(
options: Options<CreateMilestoneAgeGroupData, ThrowOnError>
) => {
return (options?.client ?? client).post<
CreateMilestoneAgeGroupResponse,
CreateMilestoneAgeGroupError,
ThrowOnError
>({
...options,
url: '/admin/milestone-age-groups/'
});
};

/**
* Delete Milestone Age Group
*/
export const deleteMilestoneAgeGroup = <ThrowOnError extends boolean = false>(
options: Options<DeleteMilestoneAgeGroupData, ThrowOnError>
) => {
return (options?.client ?? client).delete<
DeleteMilestoneAgeGroupResponse,
DeleteMilestoneAgeGroupError,
ThrowOnError
>({
...options,
url: '/admin/milestone-age-groups/{milestone_age_group_id}'
});
};

/**
* Get Milestone Groups Admin
*/
export const getMilestoneGroupsAdmin = <ThrowOnError extends boolean = false>(
options: Options<GetMilestoneGroupsAdminData, ThrowOnError>
options?: Options<unknown, ThrowOnError>
) => {
return (options?.client ?? client).get<
GetMilestoneGroupsAdminResponse,
Expand All @@ -360,15 +282,15 @@ export const getMilestoneGroupsAdmin = <ThrowOnError extends boolean = false>(
* Create Milestone Group Admin
*/
export const createMilestoneGroupAdmin = <ThrowOnError extends boolean = false>(
options: Options<CreateMilestoneGroupAdminData, ThrowOnError>
options?: Options<unknown, ThrowOnError>
) => {
return (options?.client ?? client).post<
CreateMilestoneGroupAdminResponse,
CreateMilestoneGroupAdminError,
ThrowOnError
>({
...options,
url: '/admin/milestone-groups/{milestone_age_group_id}'
url: '/admin/milestone-groups/'
});
};

Expand Down
Loading

0 comments on commit b94ab08

Please sign in to comment.