🐛 align profile and nullable API contracts
Browse files at this commitd3368e0a02fc147a8b56989fbbef6e70b946e206Parent: d8b8bf2- fix
- 🐛 align profile and nullable API contracts
13 changed files +29 -29
- src/api/patchCourseById.ts +2 -2
- src/api/patchEventById.ts +2 -2
- src/api/patchExamById.ts +4 -4
- src/api/patchExamQuestionById.ts +3 -3
- src/api/patchMe.ts +3 -3
- src/api/patchNoteById.ts +2 -2
- src/api/patchUserProfile.ts +3 -3
- src/api/postCourse.ts +1 -1
- src/api/postCourseExam.ts +1 -1
- src/api/postEvent.ts +1 -1
- src/api/postEventAttendance.ts +1 -1
- src/api/postNote.ts +1 -1
- src/components/users/profile-form.tsx +5 -5
src/api/patchCourseById.tsmodified+2 -2
| @@ -2,8 +2,8 @@ import { client } from "./client"; | |||
| 2 | import type { Course } from "./types"; | 2 | import type { Course } from "./types"; |
| 3 | 3 | ||
| 4 | export type PatchCourseBody = { | 4 | export type PatchCourseBody = { |
| 5 | - title?: string; | 5 | + title?: string | null; |
| 6 | - description?: string; | 6 | + description?: string | null; |
| 7 | }; | 7 | }; |
| 8 | 8 | ||
| 9 | export function patchCourseById(id: string, body: PatchCourseBody): Promise<Course> { | 9 | export function patchCourseById(id: string, body: PatchCourseBody): Promise<Course> { |
src/api/patchEventById.tsmodified+2 -2
| @@ -3,8 +3,8 @@ import type { Event } from "./types"; | |||
| 3 | 3 | ||
| 4 | /** Omitted time fields keep their value; explicit null clears them. */ | 4 | /** Omitted time fields keep their value; explicit null clears them. */ |
| 5 | export type PatchEventBody = { | 5 | export type PatchEventBody = { |
| 6 | - title?: string; | 6 | + title?: string | null; |
| 7 | - description?: string; | 7 | + description?: string | null; |
| 8 | starts_at?: number | null; | 8 | starts_at?: number | null; |
| 9 | ends_at?: number | null; | 9 | ends_at?: number | null; |
| 10 | }; | 10 | }; |
src/api/patchExamById.tsmodified+4 -4
| @@ -2,10 +2,10 @@ import { client } from "./client"; | |||
| 2 | import type { Exam } from "./types"; | 2 | import type { Exam } from "./types"; |
| 3 | 3 | ||
| 4 | export type PatchExamBody = { | 4 | export type PatchExamBody = { |
| 5 | - title?: string; | 5 | + title?: string | null; |
| 6 | - description?: string; | 6 | + description?: string | null; |
| 7 | - kind?: string; | 7 | + kind?: string | null; |
| 8 | - weight?: number; | 8 | + weight?: number | null; |
| 9 | mode?: string | null; | 9 | mode?: string | null; |
| 10 | starts_at?: number | null; | 10 | starts_at?: number | null; |
| 11 | ends_at?: number | null; | 11 | ends_at?: number | null; |
src/api/patchExamQuestionById.tsmodified+3 -3
| @@ -2,9 +2,9 @@ import { client } from "./client"; | |||
| 2 | import type { ExamQuestion, QuestionKind } from "./types"; | 2 | import type { ExamQuestion, QuestionKind } from "./types"; |
| 3 | 3 | ||
| 4 | export type PatchExamQuestionBody = { | 4 | export type PatchExamQuestionBody = { |
| 5 | - text?: string; | 5 | + text?: string | null; |
| 6 | - kind?: QuestionKind; | 6 | + kind?: QuestionKind | null; |
| 7 | - points?: number; | 7 | + points?: number | null; |
| 8 | choices?: string[] | null; | 8 | choices?: string[] | null; |
| 9 | correct?: number | null; | 9 | correct?: number | null; |
| 10 | }; | 10 | }; |
src/api/patchMe.tsmodified+3 -3
| @@ -1,6 +1,6 @@ | |||
| 1 | import { client } from "@/api/client"; | 1 | import { client } from "@/api/client"; |
| 2 | -import type { ProfileUpdate } from "@/api/types"; | 2 | +import type { ProfileUpdate, User } from "@/api/types"; |
| 3 | 3 | ||
| 4 | -export async function patchMe(body: ProfileUpdate): Promise<void> { | 4 | +export function patchMe(body: ProfileUpdate): Promise<User> { |
| 5 | - await client("/auth/me", { method: "PATCH", body }); | 5 | + return client<User>("/users/me", { method: "PATCH", body }); |
| 6 | } | 6 | } |
src/api/patchNoteById.tsmodified+2 -2
| @@ -2,8 +2,8 @@ import { client } from "./client"; | |||
| 2 | import type { Note } from "./types"; | 2 | import type { Note } from "./types"; |
| 3 | 3 | ||
| 4 | export type PatchNoteBody = { | 4 | export type PatchNoteBody = { |
| 5 | - title?: string; | 5 | + title?: string | null; |
| 6 | - content?: string; | 6 | + content?: string | null; |
| 7 | }; | 7 | }; |
| 8 | 8 | ||
| 9 | export function patchNoteById(id: string, body: PatchNoteBody): Promise<Note> { | 9 | export function patchNoteById(id: string, body: PatchNoteBody): Promise<Note> { |
src/api/patchUserProfile.tsmodified+3 -3
| @@ -1,6 +1,6 @@ | |||
| 1 | import { client } from "@/api/client"; | 1 | import { client } from "@/api/client"; |
| 2 | -import type { ProfileUpdate } from "@/api/types"; | 2 | +import type { ProfileUpdate, User } from "@/api/types"; |
| 3 | 3 | ||
| 4 | -export async function patchUserProfile(id: string, body: ProfileUpdate): Promise<void> { | 4 | +export function patchUserProfile(id: string, body: ProfileUpdate): Promise<User> { |
| 5 | - await client(`/users/${encodeURIComponent(id)}/profile`, { method: "PATCH", body }); | 5 | + return client<User>(`/users/${encodeURIComponent(id)}/profile`, { method: "PATCH", body }); |
| 6 | } | 6 | } |
src/api/postCourse.tsmodified+1 -1
| @@ -3,7 +3,7 @@ import type { Course } from "./types"; | |||
| 3 | 3 | ||
| 4 | export type PostCourseBody = { | 4 | export type PostCourseBody = { |
| 5 | title: string; | 5 | title: string; |
| 6 | - description?: string; | 6 | + description?: string | null; |
| 7 | }; | 7 | }; |
| 8 | 8 | ||
| 9 | export function postCourse(body: PostCourseBody): Promise<Course> { | 9 | export function postCourse(body: PostCourseBody): Promise<Course> { |
src/api/postCourseExam.tsmodified+1 -1
| @@ -3,7 +3,7 @@ import type { Exam } from "./types"; | |||
| 3 | 3 | ||
| 4 | export type PostCourseExamBody = { | 4 | export type PostCourseExamBody = { |
| 5 | title: string; | 5 | title: string; |
| 6 | - description?: string; | 6 | + description?: string | null; |
| 7 | kind: string; | 7 | kind: string; |
| 8 | weight: number; | 8 | weight: number; |
| 9 | mode?: string | null; | 9 | mode?: string | null; |
src/api/postEvent.tsmodified+1 -1
| @@ -3,7 +3,7 @@ import type { Event } from "./types"; | |||
| 3 | 3 | ||
| 4 | export type PostEventBody = { | 4 | export type PostEventBody = { |
| 5 | title: string; | 5 | title: string; |
| 6 | - description?: string; | 6 | + description?: string | null; |
| 7 | starts_at?: number | null; | 7 | starts_at?: number | null; |
| 8 | ends_at?: number | null; | 8 | ends_at?: number | null; |
| 9 | }; | 9 | }; |
src/api/postEventAttendance.tsmodified+1 -1
| @@ -3,7 +3,7 @@ import type { Attendance, AttendanceStatus } from "./types"; | |||
| 3 | 3 | ||
| 4 | export type PostEventAttendanceBody = { | 4 | export type PostEventAttendanceBody = { |
| 5 | status: AttendanceStatus; | 5 | status: AttendanceStatus; |
| 6 | - user_id?: string; | 6 | + user_id?: string | null; |
| 7 | }; | 7 | }; |
| 8 | 8 | ||
| 9 | export function postEventAttendance( | 9 | export function postEventAttendance( |
src/api/postNote.tsmodified+1 -1
| @@ -3,7 +3,7 @@ import type { Note } from "./types"; | |||
| 3 | 3 | ||
| 4 | export type PostNoteBody = { | 4 | export type PostNoteBody = { |
| 5 | title: string; | 5 | title: string; |
| 6 | - content?: string; | 6 | + content?: string | null; |
| 7 | }; | 7 | }; |
| 8 | 8 | ||
| 9 | export function postNote(body: PostNoteBody): Promise<Note> { | 9 | export function postNote(body: PostNoteBody): Promise<Note> { |
src/components/users/profile-form.tsxmodified+5 -5
| @@ -47,11 +47,11 @@ export function ProfileForm(props: { user: User; onSaved: () => void }) { | |||
| 47 | const e = email().trim(); | 47 | const e = email().trim(); |
| 48 | const p = phone().trim(); | 48 | const p = phone().trim(); |
| 49 | const d = birthDate().trim(); | 49 | const d = birthDate().trim(); |
| 50 | - if (n !== (props.user.name ?? "")) b.name = n || null; | 50 | + if (n !== (props.user.name ?? "")) b.name = n; |
| 51 | - if (s !== (props.user.surname ?? "")) b.surname = s || null; | 51 | + if (s !== (props.user.surname ?? "")) b.surname = s; |
| 52 | - if (e !== (props.user.email ?? "")) b.email = e || null; | 52 | + if (e !== (props.user.email ?? "")) b.email = e; |
| 53 | - if (p !== (props.user.phone ?? "")) b.phone = p || null; | 53 | + if (p !== (props.user.phone ?? "")) b.phone = p; |
| 54 | - if (d !== (props.user.birth_date ?? "")) b.birth_date = d || null; | 54 | + if (d !== (props.user.birth_date ?? "")) b.birth_date = d; |
| 55 | return b; | 55 | return b; |
| 56 | }; | 56 | }; |
| 57 | 57 | ||