Skip to content

Commit

Permalink
refactor: Use full page forms instead of modals (#202)
Browse files Browse the repository at this point in the history
* refactor: add id and message to create category response

* refactor: convert category creation from modal to standalone page

* refactor: add id to create lesson response

* refactor: convert lesson creation from modal to standalone page

* refactor: add id to create course response

* refactor: convert courses creation from modal to standalone page

* feat: create user method

* refactor: convert users creation from modal to standalone page

* refactor: fix typo, and update barrel files

* refactor: add missing id to response validation

* feat: create and swap icons in admin sidebar

* refactor: transform lesson item form modals into pages

* refactor: apply review feedback
  • Loading branch information
piotr-pajak authored Nov 4, 2024
1 parent e7b0760 commit a83fbcc
Show file tree
Hide file tree
Showing 58 changed files with 1,916 additions and 1,817 deletions.
2 changes: 1 addition & 1 deletion apps/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ConditionalModule, ConfigModule, ConfigService } from "@nestjs/config";
import { DrizzlePostgresModule } from "@knaadh/nestjs-drizzle-postgres";
import { JwtModule } from "@nestjs/jwt";
import { Module } from "@nestjs/common";
import { UsersModule } from "./users/users.module";
import * as schema from "./storage/schema";
import database from "./common/configuration/database";
import jwtConfig from "./common/configuration/jwt";
Expand All @@ -25,6 +24,7 @@ import { QuestionsModule } from "./questions/questions.module";
import { StudentCompletedLessonItemsModule } from "./studentCompletedLessonItem/studentCompletedLessonItems.module";
import { S3Module } from "./file/s3.module";
import { StripeModule } from "./stripe/stripe.module";
import { UsersModule } from "src/users/users.module";

@Module({
imports: [
Expand Down
28 changes: 18 additions & 10 deletions apps/api/src/categories/api/categories.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,27 @@ import {
BaseResponse,
paginatedResponse,
PaginatedResponse,
UUIDSchema,
type UUIDType,
} from "src/common";
import { CurrentUser } from "src/common/decorators/user.decorator";
import { UserRole } from "src/users/schemas/user-roles";
import type { UserRole } from "src/users/schemas/user-roles";
import { CategoriesService } from "../categories.service";
import {
AllCategoriesResponse,
CategorySchema,
type AllCategoriesResponse,
type CategorySchema,
categorySchema,
} from "../schemas/category.schema";
import {
SortCategoryFieldsOptions,
type SortCategoryFieldsOptions,
sortCategoryFieldsOptions,
} from "../schemas/categoryQuery";
import {
CreateCategoryBody,
type CreateCategoryBody,
createCategorySchema,
} from "../schemas/createCategorySchema";
import {
UpdateCategoryBody,
type UpdateCategoryBody,
updateCategorySchema,
} from "../schemas/updateCategorySchema";

Expand Down Expand Up @@ -96,11 +98,17 @@ export class CategoriesController {
schema: createCategorySchema,
},
],
response: baseResponse(
Type.Object({ id: UUIDSchema, message: Type.String() }),
),
})
async createCategory(@Body() createCategoryBody: CreateCategoryBody) {
return new BaseResponse(
await this.categoriesService.createCategory(createCategoryBody),
);
async createCategory(
@Body() createCategoryBody: CreateCategoryBody,
): Promise<BaseResponse<{ id: UUIDType; message: string }>> {
const { id } =
await this.categoriesService.createCategory(createCategoryBody);

return new BaseResponse({ id, message: "Category created" });
}

@Patch(":id")
Expand Down
19 changes: 13 additions & 6 deletions apps/api/src/courses/api/courses.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
nullResponse,
PaginatedResponse,
UUIDSchema,
type UUIDType,
} from "src/common";
import { CurrentUser } from "src/common/decorators/user.decorator";
import { CoursesService } from "../courses.service";
Expand All @@ -29,7 +30,7 @@ import {
type SortCourseFieldsOptions,
} from "../schemas/courseQuery";
import {
CreateCourseBody,
type CreateCourseBody,
createCourseSchema,
} from "../schemas/createCourse.schema";
import {
Expand All @@ -38,7 +39,7 @@ import {
} from "../schemas/showCourseCommon.schema";
import { allCoursesValidation } from "./validations";
import {
UpdateCourseBody,
type UpdateCourseBody,
updateCourseSchema,
} from "../schemas/updateCourse.schema";
import { RolesGuard } from "src/common/guards/roles.guard";
Expand Down Expand Up @@ -190,14 +191,20 @@ export class CoursesController {
@Post()
@Validate({
request: [{ type: "body", schema: createCourseSchema }],
response: baseResponse(Type.Object({ message: Type.String() })),
response: baseResponse(
Type.Object({ id: UUIDSchema, message: Type.String() }),
),
})
async createCourse(
@Body() createCourseBody: CreateCourseBody,
@CurrentUser("userId") currentUserId: string,
): Promise<BaseResponse<{ message: string }>> {
await this.coursesService.createCourse(createCourseBody, currentUserId);
return new BaseResponse({ message: "Course enrolled successfully" });
): Promise<BaseResponse<{ id: UUIDType; message: string }>> {
const { id } = await this.coursesService.createCourse(
createCourseBody,
currentUserId,
);

return new BaseResponse({ id, message: "Course created successfully" });
}

@Patch(":id")
Expand Down
2 changes: 2 additions & 0 deletions apps/api/src/lessons/adminLessons.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ export class AdminLessonsService {
);

if (!lesson) throw new NotFoundException("Lesson not found");

return { id: lesson.id };
}

async updateLesson(id: string, body: UpdateLessonBody) {
Expand Down
71 changes: 44 additions & 27 deletions apps/api/src/lessons/api/lessons.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
paginatedResponse,
PaginatedResponse,
UUIDSchema,
UUIDType,
type UUIDType,
} from "src/common";
import { Roles } from "src/common/decorators/roles.decorator";
import { CurrentUser } from "src/common/decorators/user.decorator";
Expand All @@ -26,34 +26,34 @@ import type { UserRole } from "src/users/schemas/user-roles";
import { AdminLessonItemsService } from "../adminLessonItems.service";
import { LessonsService } from "../lessons.service";
import {
AllLessonsResponse,
type AllLessonsResponse,
allLessonsSchema,
CreateLessonBody,
type CreateLessonBody,
createLessonSchema,
type ShowLessonResponse,
showLessonSchema,
UpdateLessonBody,
type UpdateLessonBody,
updateLessonSchema,
} from "../schemas/lesson.schema";
import {
FileInsertType,
type FileInsertType,
fileUpdateSchema,
GetAllLessonItemsResponse,
type GetAllLessonItemsResponse,
GetAllLessonItemsResponseSchema,
GetSingleLessonItemsResponse,
type GetSingleLessonItemsResponse,
GetSingleLessonItemsResponseSchema,
QuestionInsertType,
type QuestionInsertType,
questionUpdateSchema,
TextBlockInsertType,
type TextBlockInsertType,
textBlockUpdateSchema,
UpdateFileBody,
UpdateQuestionBody,
UpdateTextBlockBody,
type UpdateFileBody,
type UpdateQuestionBody,
type UpdateTextBlockBody,
} from "../schemas/lessonItem.schema";
import {
LessonsFilterSchema,
type LessonsFilterSchema,
sortLessonFieldsOptions,
SortLessonFieldsOptions,
type SortLessonFieldsOptions,
} from "../schemas/lessonQuery";
import { AdminLessonsService } from "../adminLessons.service";

Expand Down Expand Up @@ -165,14 +165,20 @@ export class LessonsController {
schema: createLessonSchema,
},
],
response: baseResponse(Type.Object({ message: Type.String() })),
response: baseResponse(
Type.Object({ id: UUIDSchema, message: Type.String() }),
),
})
async createLesson(
@Body() createLessonBody: CreateLessonBody,
@CurrentUser("userId") userId: string,
): Promise<BaseResponse<{ message: string }>> {
await this.adminLessonsService.createLesson(createLessonBody, userId);
return new BaseResponse({ message: "Lesson created successfully" });
): Promise<BaseResponse<{ id: UUIDType; message: string }>> {
const { id } = await this.adminLessonsService.createLesson(
createLessonBody,
userId,
);

return new BaseResponse({ id, message: "Lesson created successfully" });
}

@Patch("lesson")
Expand Down Expand Up @@ -513,6 +519,7 @@ export class LessonsController {
@Body() body: UpdateFileBody,
): Promise<BaseResponse<{ message: string }>> {
await this.adminLessonItemsService.updateFileItem(id, body);

return new BaseResponse({ message: "File updated successfully" });
}

Expand All @@ -530,14 +537,20 @@ export class LessonsController {
}),
},
],
response: baseResponse(Type.Object({ message: Type.String() })),
response: baseResponse(
Type.Object({ id: UUIDSchema, message: Type.String() }),
),
})
async createTextBlock(
@Body() body: TextBlockInsertType,
@CurrentUser("userId") userId: string,
): Promise<BaseResponse<{ message: string }>> {
await this.adminLessonItemsService.createTextBlock(body, userId);
return new BaseResponse({ message: "Text block created successfully" });
): Promise<BaseResponse<{ id: UUIDType; message: string }>> {
const { id } = await this.adminLessonItemsService.createTextBlock(
body,
userId,
);

return new BaseResponse({ id, message: "Text block created successfully" });
}

@Post("create-question")
Expand Down Expand Up @@ -568,9 +581,10 @@ export class LessonsController {
body,
userId,
);

return new BaseResponse({
message: "Question created successfully",
questionId: id,
message: "Question created successfully",
});
}

Expand Down Expand Up @@ -670,13 +684,16 @@ export class LessonsController {
}),
},
],
response: baseResponse(Type.Object({ message: Type.String() })),
response: baseResponse(
Type.Object({ id: UUIDSchema, message: Type.String() }),
),
})
async createFile(
@Body() body: FileInsertType,
@CurrentUser("userId") userId: string,
): Promise<BaseResponse<{ message: string }>> {
await this.adminLessonItemsService.createFile(body, userId);
return new BaseResponse({ message: "File created successfully" });
): Promise<BaseResponse<{ id: UUIDType; message: string }>> {
const { id } = await this.adminLessonItemsService.createFile(body, userId);

return new BaseResponse({ id, message: "File created successfully" });
}
}
Loading

0 comments on commit a83fbcc

Please sign in to comment.