Spaces:
Running
Running
Merge pull request #49 from Modarb-Ai-Trainer/feat/exercises
Browse files- src/common/models/equipment.model.ts +19 -0
- src/common/models/exercise.model.ts +10 -4
- src/common/models/muscle.model.ts +19 -0
- src/common/serializers/equipment.serialization.ts +12 -0
- src/common/serializers/exercise.serialization.ts +0 -2
- src/common/serializers/muscle.serialization.ts +12 -0
- src/modules/console/modules/equipments/controllers/equipments.controller.ts +101 -0
- src/modules/console/modules/equipments/services/equipments.service.ts +4 -0
- src/modules/console/modules/equipments/validations/create-equipment.validation.ts +19 -0
- src/modules/console/modules/equipments/validations/update-equipment.validation.ts +19 -0
- src/modules/console/modules/muscles/controllers/muscles.controller.ts +101 -0
- src/modules/console/modules/muscles/services/muscles.service.ts +4 -0
- src/modules/console/modules/muscles/validations/create-muscle.validation.ts +19 -0
- src/modules/console/modules/muscles/validations/update-muscle.validation.ts +19 -0
src/common/models/equipment.model.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import mongoose from "mongoose";
|
| 2 |
+
const { Schema } = mongoose;
|
| 3 |
+
|
| 4 |
+
export interface IEquipment {
|
| 5 |
+
name: string;
|
| 6 |
+
image: string;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
const equipmentSchema = new Schema({
|
| 10 |
+
name: { type: String, required: true, unique: true, dropDups: true },
|
| 11 |
+
image: { type: String, required: true },
|
| 12 |
+
});
|
| 13 |
+
|
| 14 |
+
export type EquipmentDocument = IEquipment & mongoose.Document;
|
| 15 |
+
|
| 16 |
+
export const Equipment = mongoose.model<EquipmentDocument>(
|
| 17 |
+
"equipments",
|
| 18 |
+
equipmentSchema
|
| 19 |
+
);
|
src/common/models/exercise.model.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import mongoose from "mongoose";
|
| 2 |
const { Schema } = mongoose;
|
| 3 |
|
| 4 |
export interface IExercise {
|
|
@@ -13,8 +13,11 @@ export interface IExercise {
|
|
| 13 |
sets: number;
|
| 14 |
instructions: string;
|
| 15 |
benefits: string;
|
| 16 |
-
targetMuscles:
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
media: {
|
| 19 |
type: "image" | "video";
|
| 20 |
url: string;
|
|
@@ -33,7 +36,10 @@ const exerciseSchema = new Schema({
|
|
| 33 |
sets: { type: Number, required: true },
|
| 34 |
instructions: { type: String, required: true },
|
| 35 |
benefits: { type: String, required: true },
|
| 36 |
-
targetMuscles:
|
|
|
|
|
|
|
|
|
|
| 37 |
equipments: [{ type: Schema.Types.ObjectId, ref: "equipments" }],
|
| 38 |
media: {
|
| 39 |
type: {
|
|
|
|
| 1 |
+
import mongoose, { ObjectId } from "mongoose";
|
| 2 |
const { Schema } = mongoose;
|
| 3 |
|
| 4 |
export interface IExercise {
|
|
|
|
| 13 |
sets: number;
|
| 14 |
instructions: string;
|
| 15 |
benefits: string;
|
| 16 |
+
targetMuscles: {
|
| 17 |
+
primary: ObjectId;
|
| 18 |
+
secondary: ObjectId;
|
| 19 |
+
}
|
| 20 |
+
equipments: ObjectId[];
|
| 21 |
media: {
|
| 22 |
type: "image" | "video";
|
| 23 |
url: string;
|
|
|
|
| 36 |
sets: { type: Number, required: true },
|
| 37 |
instructions: { type: String, required: true },
|
| 38 |
benefits: { type: String, required: true },
|
| 39 |
+
targetMuscles: {
|
| 40 |
+
primary: { type: Schema.Types.ObjectId, ref: "muscles" },
|
| 41 |
+
secondary: { type: Schema.Types.ObjectId, ref: "muscles" },
|
| 42 |
+
},
|
| 43 |
equipments: [{ type: Schema.Types.ObjectId, ref: "equipments" }],
|
| 44 |
media: {
|
| 45 |
type: {
|
src/common/models/muscle.model.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import mongoose from "mongoose";
|
| 2 |
+
const { Schema } = mongoose;
|
| 3 |
+
|
| 4 |
+
export interface IMuscle {
|
| 5 |
+
name: string;
|
| 6 |
+
image: string;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
const muscleSchema = new Schema({
|
| 10 |
+
name: { type: String, required: true, unique: true, dropDups: true },
|
| 11 |
+
image: { type: String, required: true },
|
| 12 |
+
});
|
| 13 |
+
|
| 14 |
+
export type MuscleDocument = IMuscle & mongoose.Document;
|
| 15 |
+
|
| 16 |
+
export const Muscle = mongoose.model<MuscleDocument>(
|
| 17 |
+
"muscles",
|
| 18 |
+
muscleSchema
|
| 19 |
+
);
|
src/common/serializers/equipment.serialization.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Expose } from "class-transformer";
|
| 2 |
+
|
| 3 |
+
export class MuscleSerialization {
|
| 4 |
+
@Expose({ name: "_id" })
|
| 5 |
+
id: string;
|
| 6 |
+
|
| 7 |
+
@Expose()
|
| 8 |
+
name: string;
|
| 9 |
+
|
| 10 |
+
@Expose()
|
| 11 |
+
image: string;
|
| 12 |
+
}
|
src/common/serializers/exercise.serialization.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
import { Expose, Transform } from "class-transformer";
|
| 2 |
import { serialize } from "@helpers/serialize";
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
class ExpectedDurationRange {
|
| 7 |
@Expose()
|
| 8 |
min: number;
|
|
|
|
| 1 |
import { Expose, Transform } from "class-transformer";
|
| 2 |
import { serialize } from "@helpers/serialize";
|
| 3 |
|
|
|
|
|
|
|
| 4 |
class ExpectedDurationRange {
|
| 5 |
@Expose()
|
| 6 |
min: number;
|
src/common/serializers/muscle.serialization.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Expose } from "class-transformer";
|
| 2 |
+
|
| 3 |
+
export class EquipmentSerialization {
|
| 4 |
+
@Expose({ name: "_id" })
|
| 5 |
+
id: string;
|
| 6 |
+
|
| 7 |
+
@Expose()
|
| 8 |
+
name: string;
|
| 9 |
+
|
| 10 |
+
@Expose()
|
| 11 |
+
image: string;
|
| 12 |
+
}
|
src/modules/console/modules/equipments/controllers/equipments.controller.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Request, Response } from "express";
|
| 2 |
+
import { JsonResponse } from "@lib/responses/json-response";
|
| 3 |
+
import { parsePaginationQuery } from "@helpers/pagination";
|
| 4 |
+
import { asyncHandler } from "@helpers/async-handler";
|
| 5 |
+
import { paramsValidator, bodyValidator } from "@helpers/validation.helper";
|
| 6 |
+
import { BaseController } from "@lib/controllers/controller.base";
|
| 7 |
+
import { Prefix } from "@lib/decorators/prefix.decorator";
|
| 8 |
+
import { serialize } from "@helpers/serialize";
|
| 9 |
+
import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
|
| 10 |
+
import { AdminGuardMiddleware } from "modules/console/common/guards/admins.guard";
|
| 11 |
+
import { EquipmentsService } from "../services/equipments.service";
|
| 12 |
+
import { createEquipmentchema } from "../validations/create-equipment.validation";
|
| 13 |
+
import { updateEquipmentSchema } from "../validations/update-equipment.validation";
|
| 14 |
+
import { EquipmentSerialization } from "@common/serializers/muscle.serialization";
|
| 15 |
+
|
| 16 |
+
@Prefix("/console/equipments")
|
| 17 |
+
@ControllerMiddleware(AdminGuardMiddleware({}))
|
| 18 |
+
export class EquipmentsController extends BaseController {
|
| 19 |
+
private equipmentsService = new EquipmentsService();
|
| 20 |
+
|
| 21 |
+
setRoutes() {
|
| 22 |
+
this.router.get("/", asyncHandler(this.list));
|
| 23 |
+
this.router.get("/:id", paramsValidator("id"), asyncHandler(this.get));
|
| 24 |
+
this.router.post("/",
|
| 25 |
+
bodyValidator(createEquipmentchema),
|
| 26 |
+
asyncHandler(this.create));
|
| 27 |
+
this.router.patch(
|
| 28 |
+
"/:id",
|
| 29 |
+
paramsValidator("id"),
|
| 30 |
+
bodyValidator(updateEquipmentSchema),
|
| 31 |
+
asyncHandler(this.update)
|
| 32 |
+
);
|
| 33 |
+
this.router.delete(
|
| 34 |
+
"/:id",
|
| 35 |
+
paramsValidator("id"),
|
| 36 |
+
asyncHandler(this.delete)
|
| 37 |
+
);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
list = async (req: Request, res: Response) => {
|
| 41 |
+
const paginationQuery = parsePaginationQuery(req.query);
|
| 42 |
+
const { docs, paginationData } = await this.equipmentsService.list(
|
| 43 |
+
{},
|
| 44 |
+
paginationQuery
|
| 45 |
+
);
|
| 46 |
+
|
| 47 |
+
return JsonResponse.success(
|
| 48 |
+
{
|
| 49 |
+
data: serialize(docs, EquipmentSerialization),
|
| 50 |
+
meta: paginationData,
|
| 51 |
+
},
|
| 52 |
+
res
|
| 53 |
+
);
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
get = async (req: Request, res: Response) => {
|
| 57 |
+
const data = await this.equipmentsService.findOneOrFail({
|
| 58 |
+
_id: req.params.id,
|
| 59 |
+
});
|
| 60 |
+
return JsonResponse.success(
|
| 61 |
+
{
|
| 62 |
+
data: serialize(data.toJSON(), EquipmentSerialization),
|
| 63 |
+
},
|
| 64 |
+
res
|
| 65 |
+
);
|
| 66 |
+
};
|
| 67 |
+
|
| 68 |
+
create = async (req: Request, res: Response) => {
|
| 69 |
+
const data = await this.equipmentsService.create(req.body);
|
| 70 |
+
return JsonResponse.success(
|
| 71 |
+
{
|
| 72 |
+
status: 201,
|
| 73 |
+
data: serialize(data.toJSON(), EquipmentSerialization),
|
| 74 |
+
},
|
| 75 |
+
res
|
| 76 |
+
);
|
| 77 |
+
};
|
| 78 |
+
|
| 79 |
+
update = async (req: Request, res: Response) => {
|
| 80 |
+
const data = await this.equipmentsService.updateOne(
|
| 81 |
+
{ _id: req.params.id },
|
| 82 |
+
req.body
|
| 83 |
+
);
|
| 84 |
+
return JsonResponse.success(
|
| 85 |
+
{
|
| 86 |
+
data: serialize(data.toJSON(), EquipmentSerialization),
|
| 87 |
+
},
|
| 88 |
+
res
|
| 89 |
+
);
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
delete = async (req: Request, res: Response) => {
|
| 93 |
+
const data = await this.equipmentsService.deleteOne({ _id: req.params.id });
|
| 94 |
+
return JsonResponse.success(
|
| 95 |
+
{
|
| 96 |
+
data: serialize(data.toJSON(), EquipmentSerialization),
|
| 97 |
+
},
|
| 98 |
+
res
|
| 99 |
+
);
|
| 100 |
+
};
|
| 101 |
+
};
|
src/modules/console/modules/equipments/services/equipments.service.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Equipment } from "@common/models/equipment.model";
|
| 2 |
+
import { CrudService } from "@lib/services/crud.service";
|
| 3 |
+
|
| 4 |
+
export class EquipmentsService extends CrudService(Equipment) {};
|
src/modules/console/modules/equipments/validations/create-equipment.validation.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as joi from "joi";
|
| 2 |
+
import { createSchema } from "@helpers/create-schema";
|
| 3 |
+
|
| 4 |
+
export interface ICreateEquipment{
|
| 5 |
+
name: string;
|
| 6 |
+
image: string;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
export const createEquipmentchema = createSchema<ICreateEquipment>({
|
| 10 |
+
name: joi.string().empty().required().messages({
|
| 11 |
+
"string.base": "please enter a valid name",
|
| 12 |
+
"any.required": "name is required",
|
| 13 |
+
"string.empty": "name can not be empty",
|
| 14 |
+
}),
|
| 15 |
+
image: joi.string().empty().required().messages({
|
| 16 |
+
"string.base": "please enter a valid image url",
|
| 17 |
+
"string.empty": "image url can not be empty",
|
| 18 |
+
}),
|
| 19 |
+
});
|
src/modules/console/modules/equipments/validations/update-equipment.validation.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as joi from "joi";
|
| 2 |
+
import { createSchema } from "@helpers/create-schema";
|
| 3 |
+
|
| 4 |
+
export interface IUpdateEquipment {
|
| 5 |
+
name?: string;
|
| 6 |
+
image?: string;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
export const updateEquipmentSchema = createSchema<IUpdateEquipment>({
|
| 11 |
+
name: joi.string().empty().optional().messages({
|
| 12 |
+
"string.base": "please enter a valid name",
|
| 13 |
+
"string.empty": "name can not be empty",
|
| 14 |
+
}),
|
| 15 |
+
image: joi.string().empty().optional().messages({
|
| 16 |
+
"string.base": "please enter a valid image url",
|
| 17 |
+
"string.empty": "image url can not be empty",
|
| 18 |
+
}),
|
| 19 |
+
});
|
src/modules/console/modules/muscles/controllers/muscles.controller.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Request, Response } from "express";
|
| 2 |
+
import { JsonResponse } from "@lib/responses/json-response";
|
| 3 |
+
import { parsePaginationQuery } from "@helpers/pagination";
|
| 4 |
+
import { asyncHandler } from "@helpers/async-handler";
|
| 5 |
+
import { paramsValidator, bodyValidator } from "@helpers/validation.helper";
|
| 6 |
+
import { BaseController } from "@lib/controllers/controller.base";
|
| 7 |
+
import { Prefix } from "@lib/decorators/prefix.decorator";
|
| 8 |
+
import { serialize } from "@helpers/serialize";
|
| 9 |
+
import { ControllerMiddleware } from "@lib/decorators/controller-middleware.decorator";
|
| 10 |
+
import { AdminGuardMiddleware } from "modules/console/common/guards/admins.guard";
|
| 11 |
+
import { MusclesService } from "../services/muscles.service";
|
| 12 |
+
import { createMusclechema } from "../validations/create-muscle.validation";
|
| 13 |
+
import { updateMuscleSchema } from "../validations/update-muscle.validation";
|
| 14 |
+
import { MuscleSerialization } from "@common/serializers/equipment.serialization";
|
| 15 |
+
|
| 16 |
+
@Prefix("/console/muscles")
|
| 17 |
+
@ControllerMiddleware(AdminGuardMiddleware({}))
|
| 18 |
+
export class MusclesController extends BaseController {
|
| 19 |
+
private musclesService = new MusclesService();
|
| 20 |
+
|
| 21 |
+
setRoutes() {
|
| 22 |
+
this.router.get("/", asyncHandler(this.list));
|
| 23 |
+
this.router.get("/:id", paramsValidator("id"), asyncHandler(this.get));
|
| 24 |
+
this.router.post("/",
|
| 25 |
+
bodyValidator(createMusclechema),
|
| 26 |
+
asyncHandler(this.create));
|
| 27 |
+
this.router.patch(
|
| 28 |
+
"/:id",
|
| 29 |
+
paramsValidator("id"),
|
| 30 |
+
bodyValidator(updateMuscleSchema),
|
| 31 |
+
asyncHandler(this.update)
|
| 32 |
+
);
|
| 33 |
+
this.router.delete(
|
| 34 |
+
"/:id",
|
| 35 |
+
paramsValidator("id"),
|
| 36 |
+
asyncHandler(this.delete)
|
| 37 |
+
);
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
list = async (req: Request, res: Response) => {
|
| 41 |
+
const paginationQuery = parsePaginationQuery(req.query);
|
| 42 |
+
const { docs, paginationData } = await this.musclesService.list(
|
| 43 |
+
{},
|
| 44 |
+
paginationQuery
|
| 45 |
+
);
|
| 46 |
+
|
| 47 |
+
return JsonResponse.success(
|
| 48 |
+
{
|
| 49 |
+
data: serialize(docs, MuscleSerialization),
|
| 50 |
+
meta: paginationData,
|
| 51 |
+
},
|
| 52 |
+
res
|
| 53 |
+
);
|
| 54 |
+
};
|
| 55 |
+
|
| 56 |
+
get = async (req: Request, res: Response) => {
|
| 57 |
+
const data = await this.musclesService.findOneOrFail({
|
| 58 |
+
_id: req.params.id,
|
| 59 |
+
});
|
| 60 |
+
return JsonResponse.success(
|
| 61 |
+
{
|
| 62 |
+
data: serialize(data.toJSON(), MuscleSerialization),
|
| 63 |
+
},
|
| 64 |
+
res
|
| 65 |
+
);
|
| 66 |
+
};
|
| 67 |
+
|
| 68 |
+
create = async (req: Request, res: Response) => {
|
| 69 |
+
const data = await this.musclesService.create(req.body);
|
| 70 |
+
return JsonResponse.success(
|
| 71 |
+
{
|
| 72 |
+
status: 201,
|
| 73 |
+
data: serialize(data.toJSON(), MuscleSerialization),
|
| 74 |
+
},
|
| 75 |
+
res
|
| 76 |
+
);
|
| 77 |
+
};
|
| 78 |
+
|
| 79 |
+
update = async (req: Request, res: Response) => {
|
| 80 |
+
const data = await this.musclesService.updateOne(
|
| 81 |
+
{ _id: req.params.id },
|
| 82 |
+
req.body
|
| 83 |
+
);
|
| 84 |
+
return JsonResponse.success(
|
| 85 |
+
{
|
| 86 |
+
data: serialize(data.toJSON(), MuscleSerialization),
|
| 87 |
+
},
|
| 88 |
+
res
|
| 89 |
+
);
|
| 90 |
+
};
|
| 91 |
+
|
| 92 |
+
delete = async (req: Request, res: Response) => {
|
| 93 |
+
const data = await this.musclesService.deleteOne({ _id: req.params.id });
|
| 94 |
+
return JsonResponse.success(
|
| 95 |
+
{
|
| 96 |
+
data: serialize(data.toJSON(), MuscleSerialization),
|
| 97 |
+
},
|
| 98 |
+
res
|
| 99 |
+
);
|
| 100 |
+
};
|
| 101 |
+
};
|
src/modules/console/modules/muscles/services/muscles.service.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { Muscle } from "@common/models/muscle.model";
|
| 2 |
+
import { CrudService } from "@lib/services/crud.service";
|
| 3 |
+
|
| 4 |
+
export class MusclesService extends CrudService(Muscle) {};
|
src/modules/console/modules/muscles/validations/create-muscle.validation.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as joi from "joi";
|
| 2 |
+
import { createSchema } from "@helpers/create-schema";
|
| 3 |
+
|
| 4 |
+
export interface ICreateMuscle{
|
| 5 |
+
name: string;
|
| 6 |
+
image: string;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
export const createMusclechema = createSchema<ICreateMuscle>({
|
| 10 |
+
name: joi.string().empty().required().messages({
|
| 11 |
+
"string.base": "please enter a valid name",
|
| 12 |
+
"any.required": "name is required",
|
| 13 |
+
"string.empty": "name can not be empty",
|
| 14 |
+
}),
|
| 15 |
+
image: joi.string().empty().required().messages({
|
| 16 |
+
"string.base": "please enter a valid image url",
|
| 17 |
+
"string.empty": "image url can not be empty",
|
| 18 |
+
}),
|
| 19 |
+
});
|
src/modules/console/modules/muscles/validations/update-muscle.validation.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as joi from "joi";
|
| 2 |
+
import { createSchema } from "@helpers/create-schema";
|
| 3 |
+
|
| 4 |
+
export interface IUpdateMuscle {
|
| 5 |
+
name?: string;
|
| 6 |
+
image?: string;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
export const updateMuscleSchema = createSchema<IUpdateMuscle>({
|
| 11 |
+
name: joi.string().empty().optional().messages({
|
| 12 |
+
"string.base": "please enter a valid name",
|
| 13 |
+
"string.empty": "name can not be empty",
|
| 14 |
+
}),
|
| 15 |
+
image: joi.string().empty().optional().messages({
|
| 16 |
+
"string.base": "please enter a valid image url",
|
| 17 |
+
"string.empty": "image url can not be empty",
|
| 18 |
+
}),
|
| 19 |
+
});
|