Skip to content

Commit 8905d5a

Browse files
committed
fix types
Signed-off-by: Kirill Mokevnin <[email protected]>
1 parent 1ed327c commit 8905d5a

File tree

4 files changed

+124
-38
lines changed

4 files changed

+124
-38
lines changed

routes/api/courses.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { asc, eq } from 'drizzle-orm';
33
import * as schemas from '../../db/schema.ts';
44
import { ensure, getPagingOptions } from '../../lib/utils.ts';
55
import type { RouteHandlers } from '../../types/handlers/fastify.gen.ts';
6-
import type { Course } from '../../types/index.ts';
6+
import type {
7+
CourseCreateDto,
8+
CourseEditDto,
9+
} from '../../types/handlers/index.ts';
710
import CourseValidator from '../../validators/CourseValidator.ts';
811

912
export default {
@@ -26,16 +29,16 @@ export default {
2629

2730
async coursesCreate(request, reply) {
2831
await request.jwtVerify();
29-
const validated = await CourseValidator.validate(
32+
const validated = await CourseValidator.validate<CourseCreateDto>(
3033
request.db,
31-
request.body as Course,
34+
request.body,
3235
);
3336
// attach creator id from auth if available
3437
const creatorId = request.user?.id;
3538
const values = {
3639
...validated,
3740
creatorId: creatorId,
38-
} as Course;
41+
};
3942

4043
const [course] = await request.db
4144
.insert(schemas.courses)
@@ -46,9 +49,9 @@ export default {
4649

4750
async coursesUpdate(request, reply) {
4851
await request.jwtVerify();
49-
const validated = await CourseValidator.validate(
52+
const validated = await CourseValidator.validate<CourseEditDto>(
5053
request.db,
51-
request.body as Course,
54+
request.body,
5255
);
5356
const [course] = await request.db
5457
.update(schemas.courses)

routes/api/courses/lessons.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { and, asc, eq } from 'drizzle-orm';
33
import * as schemas from '../../../db/schema.ts';
44
import { ensure, getPagingOptions } from '../../../lib/utils.ts';
55
import type { RouteHandlers } from '../../../types/handlers/fastify.gen.ts';
6-
import type { CourseLesson } from '../../../types/index.ts';
6+
import type { CourseLessonCreateDto } from '../../../types/handlers/index.ts';
77
import LessonValidator from '../../../validators/Course/LessonValidator.ts';
88

99
export default {
@@ -30,14 +30,14 @@ export default {
3030

3131
async coursesLessonsCreate(request, reply) {
3232
await request.jwtVerify();
33-
const validated = await LessonValidator.validate(
33+
const validated = await LessonValidator.validate<CourseLessonCreateDto>(
3434
request.db,
35-
request.body as CourseLesson,
35+
request.body,
3636
);
3737
const values = {
3838
...validated,
3939
courseId: request.params.courseId,
40-
} as CourseLesson;
40+
};
4141
const [lesson] = await request.db
4242
.insert(schemas.courseLessons)
4343
.values(values)

tsp-output/@typespec/openapi3/openapi.v1.json

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
}
3737
}
3838
},
39-
"required": ["data"]
39+
"required": [
40+
"data"
41+
]
4042
}
4143
}
4244
}
@@ -123,7 +125,9 @@
123125
}
124126
}
125127
},
126-
"required": ["data"]
128+
"required": [
129+
"data"
130+
]
127131
}
128132
}
129133
}
@@ -454,7 +458,9 @@
454458
}
455459
}
456460
},
457-
"required": ["data"]
461+
"required": [
462+
"data"
463+
]
458464
}
459465
}
460466
}
@@ -643,7 +649,10 @@
643649
"schemas": {
644650
"AuthInfo": {
645651
"type": "object",
646-
"required": ["email", "password"],
652+
"required": [
653+
"email",
654+
"password"
655+
],
647656
"properties": {
648657
"email": {
649658
"type": "string"
@@ -655,7 +664,11 @@
655664
},
656665
"Course": {
657666
"type": "object",
658-
"required": ["id", "name", "description"],
667+
"required": [
668+
"id",
669+
"name",
670+
"description"
671+
],
659672
"properties": {
660673
"id": {
661674
"type": "number"
@@ -670,7 +683,10 @@
670683
},
671684
"CourseCreateDTO": {
672685
"type": "object",
673-
"required": ["name", "description"],
686+
"required": [
687+
"name",
688+
"description"
689+
],
674690
"properties": {
675691
"name": {
676692
"type": "string"
@@ -693,7 +709,12 @@
693709
},
694710
"CourseLesson": {
695711
"type": "object",
696-
"required": ["id", "courseId", "name", "body"],
712+
"required": [
713+
"id",
714+
"courseId",
715+
"name",
716+
"body"
717+
],
697718
"properties": {
698719
"id": {
699720
"type": "number"
@@ -711,7 +732,10 @@
711732
},
712733
"CourseLessonCreateDTO": {
713734
"type": "object",
714-
"required": ["name", "body"],
735+
"required": [
736+
"name",
737+
"body"
738+
],
715739
"properties": {
716740
"name": {
717741
"type": "string"
@@ -787,7 +811,9 @@
787811
},
788812
"TokenInfo": {
789813
"type": "object",
790-
"required": ["token"],
814+
"required": [
815+
"token"
816+
],
791817
"properties": {
792818
"token": {
793819
"type": "string"
@@ -816,7 +842,9 @@
816842
},
817843
"UnprocessableEntityError": {
818844
"type": "object",
819-
"required": ["errors"],
845+
"required": [
846+
"errors"
847+
],
820848
"properties": {
821849
"type": {
822850
"type": "string"
@@ -848,14 +876,22 @@
848876
"type": "string"
849877
}
850878
},
851-
"required": ["message", "rule", "field"]
879+
"required": [
880+
"message",
881+
"rule",
882+
"field"
883+
]
852884
}
853885
}
854886
}
855887
},
856888
"User": {
857889
"type": "object",
858-
"required": ["id", "fullName", "email"],
890+
"required": [
891+
"id",
892+
"fullName",
893+
"email"
894+
],
859895
"properties": {
860896
"id": {
861897
"type": "number"
@@ -873,7 +909,9 @@
873909
},
874910
"UserCreateDTO": {
875911
"type": "object",
876-
"required": ["email"],
912+
"required": [
913+
"email"
914+
],
877915
"properties": {
878916
"fullName": {
879917
"type": "string"
@@ -893,7 +931,10 @@
893931
},
894932
"Versions": {
895933
"type": "string",
896-
"enum": ["v1", "v2"]
934+
"enum": [
935+
"v1",
936+
"v2"
937+
]
897938
}
898939
},
899940
"securitySchemes": {

0 commit comments

Comments
 (0)