@asad_dev/leo-generator 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +194 -0
- package/COMMAND_REFERENCE.md +412 -0
- package/README.md +486 -0
- package/dist/app/modules/imagemodule/imagemodule.constants.js +18 -0
- package/dist/app/modules/imagemodule/imagemodule.controller.js +98 -0
- package/dist/app/modules/imagemodule/imagemodule.interface.js +2 -0
- package/dist/app/modules/imagemodule/imagemodule.model.js +10 -0
- package/dist/app/modules/imagemodule/imagemodule.route.js +20 -0
- package/dist/app/modules/imagemodule/imagemodule.service.js +137 -0
- package/dist/app/modules/imagemodule/imagemodule.validation.js +12 -0
- package/dist/app/modules/skiptest/skiptest.controller.js +81 -0
- package/dist/app/modules/skiptest/skiptest.route.js +19 -0
- package/dist/app/modules/skiptest/skiptest.service.js +129 -0
- package/dist/app/modules/skiptest/skiptest.validation.js +12 -0
- package/dist/app/modules/testmodule/testmodule.constants.js +18 -0
- package/dist/app/modules/testmodule/testmodule.controller.js +81 -0
- package/dist/app/modules/testmodule/testmodule.interface.js +2 -0
- package/dist/app/modules/testmodule/testmodule.model.js +11 -0
- package/dist/app/modules/testmodule/testmodule.route.js +19 -0
- package/dist/app/modules/testmodule/testmodule.service.js +129 -0
- package/dist/app/modules/testmodule/testmodule.validation.js +14 -0
- package/dist/helpers/fileHelper.js +44 -0
- package/dist/index.js +586 -0
- package/dist/templates/constants.template.js +24 -0
- package/dist/templates/controller.template.js +108 -0
- package/dist/templates/route.template.js +68 -0
- package/dist/templates/service.template.js +184 -0
- package/dist/types.js +2 -0
- package/dist/utils/documentationUpdater.js +430 -0
- package/dist/utils/fieldParser.js +163 -0
- package/dist/utils/helperGenerator.js +87 -0
- package/dist/utils/interfaceGenerator.js +158 -0
- package/dist/utils/modelGenerator.js +140 -0
- package/dist/utils/postmanApi.js +113 -0
- package/dist/utils/postmanGenerator.js +283 -0
- package/dist/utils/swaggerGenerator.js +444 -0
- package/dist/utils/validationGenerator.js +170 -0
- package/package.json +58 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.ImagemoduleServices = void 0;
|
|
27
|
+
const http_status_codes_1 = require("http-status-codes");
|
|
28
|
+
const ApiError_1 = __importDefault(require("../../../errors/ApiError"));
|
|
29
|
+
const imagemodule_model_1 = require("./imagemodule.model");
|
|
30
|
+
const paginationHelper_1 = require("../../../helpers/paginationHelper");
|
|
31
|
+
const imagemodule_constants_1 = require("./imagemodule.constants");
|
|
32
|
+
const mongoose_1 = require("mongoose");
|
|
33
|
+
const fileHelper_1 = __importDefault(require("../../../helpers/fileHelper"));
|
|
34
|
+
const createImagemodule = (user, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
try {
|
|
36
|
+
const result = yield imagemodule_model_1.Imagemodule.create(payload);
|
|
37
|
+
if (!result) {
|
|
38
|
+
yield (0, fileHelper_1.default)(payload.images || payload.media);
|
|
39
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.BAD_REQUEST, 'Failed to create Imagemodule, please try again with valid data.');
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (payload.images || payload.media)
|
|
45
|
+
yield (0, fileHelper_1.default)(payload.images || payload.media);
|
|
46
|
+
if (error.code === 11000) {
|
|
47
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.CONFLICT, 'Duplicate entry found');
|
|
48
|
+
}
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
const getAllImagemodules = (user, filterables, pagination) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
const { searchTerm } = filterables, filterData = __rest(filterables, ["searchTerm"]);
|
|
54
|
+
const { page, skip, limit, sortBy, sortOrder } = paginationHelper_1.paginationHelper.calculatePagination(pagination);
|
|
55
|
+
const andConditions = [];
|
|
56
|
+
// Search functionality
|
|
57
|
+
if (searchTerm) {
|
|
58
|
+
andConditions.push({
|
|
59
|
+
$or: imagemodule_constants_1.imagemoduleSearchableFields.map((field) => ({
|
|
60
|
+
[field]: {
|
|
61
|
+
$regex: searchTerm,
|
|
62
|
+
$options: 'i',
|
|
63
|
+
},
|
|
64
|
+
})),
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
// Filter functionality
|
|
68
|
+
if (Object.keys(filterData).length) {
|
|
69
|
+
andConditions.push({
|
|
70
|
+
$and: Object.entries(filterData).map(([key, value]) => ({
|
|
71
|
+
[key]: value,
|
|
72
|
+
})),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const whereConditions = andConditions.length ? { $and: andConditions } : {};
|
|
76
|
+
const [result, total] = yield Promise.all([
|
|
77
|
+
imagemodule_model_1.Imagemodule
|
|
78
|
+
.find(whereConditions)
|
|
79
|
+
.skip(skip)
|
|
80
|
+
.limit(limit)
|
|
81
|
+
.sort({ [sortBy]: sortOrder }),
|
|
82
|
+
imagemodule_model_1.Imagemodule.countDocuments(whereConditions),
|
|
83
|
+
]);
|
|
84
|
+
return {
|
|
85
|
+
meta: {
|
|
86
|
+
page,
|
|
87
|
+
limit,
|
|
88
|
+
total,
|
|
89
|
+
totalPages: Math.ceil(total / limit),
|
|
90
|
+
},
|
|
91
|
+
data: result,
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
const getSingleImagemodule = (id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
|
+
if (!mongoose_1.Types.ObjectId.isValid(id)) {
|
|
96
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.BAD_REQUEST, 'Invalid Imagemodule ID');
|
|
97
|
+
}
|
|
98
|
+
const result = yield imagemodule_model_1.Imagemodule.findById(id);
|
|
99
|
+
if (!result) {
|
|
100
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.NOT_FOUND, 'Requested imagemodule not found, please try again with valid id');
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
});
|
|
104
|
+
const updateImagemodule = (id, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
+
if (!mongoose_1.Types.ObjectId.isValid(id)) {
|
|
106
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.BAD_REQUEST, 'Invalid Imagemodule ID');
|
|
107
|
+
}
|
|
108
|
+
const result = yield imagemodule_model_1.Imagemodule.findByIdAndUpdate(new mongoose_1.Types.ObjectId(id), { $set: payload }, {
|
|
109
|
+
new: true,
|
|
110
|
+
runValidators: true,
|
|
111
|
+
});
|
|
112
|
+
if (!result) {
|
|
113
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.NOT_FOUND, 'Requested imagemodule not found, please try again with valid id');
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
});
|
|
117
|
+
const deleteImagemodule = (id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
118
|
+
if (!mongoose_1.Types.ObjectId.isValid(id)) {
|
|
119
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.BAD_REQUEST, 'Invalid Imagemodule ID');
|
|
120
|
+
}
|
|
121
|
+
const result = yield imagemodule_model_1.Imagemodule.findByIdAndDelete(id);
|
|
122
|
+
if (!result) {
|
|
123
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.NOT_FOUND, 'Something went wrong while deleting imagemodule, please try again with valid id.');
|
|
124
|
+
}
|
|
125
|
+
// Remove associated files
|
|
126
|
+
if (result.image || result.images || result.media) {
|
|
127
|
+
yield (0, fileHelper_1.default)(result.image || result.images || result.media);
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
});
|
|
131
|
+
exports.ImagemoduleServices = {
|
|
132
|
+
createImagemodule,
|
|
133
|
+
getAllImagemodules,
|
|
134
|
+
getSingleImagemodule,
|
|
135
|
+
updateImagemodule,
|
|
136
|
+
deleteImagemodule,
|
|
137
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImagemoduleValidations = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.ImagemoduleValidations = {
|
|
6
|
+
create: zod_1.z.object({
|
|
7
|
+
image: zod_1.z.string(),
|
|
8
|
+
}),
|
|
9
|
+
update: zod_1.z.object({
|
|
10
|
+
image: zod_1.z.string().optional(),
|
|
11
|
+
}),
|
|
12
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.SkiptestController = void 0;
|
|
16
|
+
const skiptest_service_1 = require("./skiptest.service");
|
|
17
|
+
const catchAsync_1 = __importDefault(require("../../../shared/catchAsync"));
|
|
18
|
+
const sendResponse_1 = __importDefault(require("../../../shared/sendResponse"));
|
|
19
|
+
const http_status_codes_1 = require("http-status-codes");
|
|
20
|
+
const pick_1 = __importDefault(require("../../../shared/pick"));
|
|
21
|
+
const skiptest_constants_1 = require("./skiptest.constants");
|
|
22
|
+
const pagination_1 = require("../../../interfaces/pagination");
|
|
23
|
+
const createSkiptest = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const skiptestData = req.body;
|
|
25
|
+
const result = yield skiptest_service_1.SkiptestServices.createSkiptest(req.user, skiptestData);
|
|
26
|
+
(0, sendResponse_1.default)(res, {
|
|
27
|
+
statusCode: http_status_codes_1.StatusCodes.CREATED,
|
|
28
|
+
success: true,
|
|
29
|
+
message: 'Skiptest created successfully',
|
|
30
|
+
data: result,
|
|
31
|
+
});
|
|
32
|
+
}));
|
|
33
|
+
const updateSkiptest = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const { id } = req.params;
|
|
35
|
+
const skiptestData = req.body;
|
|
36
|
+
const result = yield skiptest_service_1.SkiptestServices.updateSkiptest(id, skiptestData);
|
|
37
|
+
(0, sendResponse_1.default)(res, {
|
|
38
|
+
statusCode: http_status_codes_1.StatusCodes.OK,
|
|
39
|
+
success: true,
|
|
40
|
+
message: 'Skiptest updated successfully',
|
|
41
|
+
data: result,
|
|
42
|
+
});
|
|
43
|
+
}));
|
|
44
|
+
const getSingleSkiptest = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
const { id } = req.params;
|
|
46
|
+
const result = yield skiptest_service_1.SkiptestServices.getSingleSkiptest(id);
|
|
47
|
+
(0, sendResponse_1.default)(res, {
|
|
48
|
+
statusCode: http_status_codes_1.StatusCodes.OK,
|
|
49
|
+
success: true,
|
|
50
|
+
message: 'Skiptest retrieved successfully',
|
|
51
|
+
data: result,
|
|
52
|
+
});
|
|
53
|
+
}));
|
|
54
|
+
const getAllSkiptests = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
const filterables = (0, pick_1.default)(req.query, skiptest_constants_1.skiptestFilterables);
|
|
56
|
+
const pagination = (0, pick_1.default)(req.query, pagination_1.paginationFields);
|
|
57
|
+
const result = yield skiptest_service_1.SkiptestServices.getAllSkiptests(req.user, filterables, pagination);
|
|
58
|
+
(0, sendResponse_1.default)(res, {
|
|
59
|
+
statusCode: http_status_codes_1.StatusCodes.OK,
|
|
60
|
+
success: true,
|
|
61
|
+
message: 'Skiptests retrieved successfully',
|
|
62
|
+
data: result,
|
|
63
|
+
});
|
|
64
|
+
}));
|
|
65
|
+
const deleteSkiptest = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
const { id } = req.params;
|
|
67
|
+
const result = yield skiptest_service_1.SkiptestServices.deleteSkiptest(id);
|
|
68
|
+
(0, sendResponse_1.default)(res, {
|
|
69
|
+
statusCode: http_status_codes_1.StatusCodes.OK,
|
|
70
|
+
success: true,
|
|
71
|
+
message: 'Skiptest deleted successfully',
|
|
72
|
+
data: result,
|
|
73
|
+
});
|
|
74
|
+
}));
|
|
75
|
+
exports.SkiptestController = {
|
|
76
|
+
createSkiptest,
|
|
77
|
+
updateSkiptest,
|
|
78
|
+
getSingleSkiptest,
|
|
79
|
+
getAllSkiptests,
|
|
80
|
+
deleteSkiptest,
|
|
81
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SkiptestRoutes = void 0;
|
|
7
|
+
const express_1 = __importDefault(require("express"));
|
|
8
|
+
const skiptest_controller_1 = require("./skiptest.controller");
|
|
9
|
+
const skiptest_validation_1 = require("./skiptest.validation");
|
|
10
|
+
const validateRequest_1 = __importDefault(require("../../middleware/validateRequest"));
|
|
11
|
+
const auth_1 = __importDefault(require("../../middleware/auth"));
|
|
12
|
+
const user_1 = require("../../../enum/user");
|
|
13
|
+
const router = express_1.default.Router();
|
|
14
|
+
router.get('/', (0, auth_1.default)(user_1.USER_ROLES.SUPER_ADMIN, user_1.USER_ROLES.ADMIN), skiptest_controller_1.SkiptestController.getAllSkiptests);
|
|
15
|
+
router.get('/:id', (0, auth_1.default)(user_1.USER_ROLES.SUPER_ADMIN, user_1.USER_ROLES.ADMIN), skiptest_controller_1.SkiptestController.getSingleSkiptest);
|
|
16
|
+
router.post('/', (0, auth_1.default)(user_1.USER_ROLES.SUPER_ADMIN, user_1.USER_ROLES.ADMIN), (0, validateRequest_1.default)(skiptest_validation_1.SkiptestValidations.createSkiptestZodSchema), skiptest_controller_1.SkiptestController.createSkiptest);
|
|
17
|
+
router.patch('/:id', (0, auth_1.default)(user_1.USER_ROLES.SUPER_ADMIN, user_1.USER_ROLES.ADMIN), (0, validateRequest_1.default)(skiptest_validation_1.SkiptestValidations.updateSkiptestZodSchema), skiptest_controller_1.SkiptestController.updateSkiptest);
|
|
18
|
+
router.delete('/:id', (0, auth_1.default)(user_1.USER_ROLES.SUPER_ADMIN, user_1.USER_ROLES.ADMIN), skiptest_controller_1.SkiptestController.deleteSkiptest);
|
|
19
|
+
exports.SkiptestRoutes = router;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.SkiptestServices = void 0;
|
|
27
|
+
const http_status_codes_1 = require("http-status-codes");
|
|
28
|
+
const ApiError_1 = __importDefault(require("../../../errors/ApiError"));
|
|
29
|
+
const skiptest_model_1 = require("./skiptest.model");
|
|
30
|
+
const paginationHelper_1 = require("../../../helpers/paginationHelper");
|
|
31
|
+
const skiptest_constants_1 = require("./skiptest.constants");
|
|
32
|
+
const mongoose_1 = require("mongoose");
|
|
33
|
+
const createSkiptest = (user, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
try {
|
|
35
|
+
const result = yield skiptest_model_1.Skiptest.create(payload);
|
|
36
|
+
if (!result) {
|
|
37
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.BAD_REQUEST, 'Failed to create Skiptest, please try again with valid data.');
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (error.code === 11000) {
|
|
43
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.CONFLICT, 'Duplicate entry found');
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
const getAllSkiptests = (user, filterables, pagination) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
const { searchTerm } = filterables, filterData = __rest(filterables, ["searchTerm"]);
|
|
50
|
+
const { page, skip, limit, sortBy, sortOrder } = paginationHelper_1.paginationHelper.calculatePagination(pagination);
|
|
51
|
+
const andConditions = [];
|
|
52
|
+
// Search functionality
|
|
53
|
+
if (searchTerm) {
|
|
54
|
+
andConditions.push({
|
|
55
|
+
$or: skiptest_constants_1.skiptestSearchableFields.map((field) => ({
|
|
56
|
+
[field]: {
|
|
57
|
+
$regex: searchTerm,
|
|
58
|
+
$options: 'i',
|
|
59
|
+
},
|
|
60
|
+
})),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
// Filter functionality
|
|
64
|
+
if (Object.keys(filterData).length) {
|
|
65
|
+
andConditions.push({
|
|
66
|
+
$and: Object.entries(filterData).map(([key, value]) => ({
|
|
67
|
+
[key]: value,
|
|
68
|
+
})),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const whereConditions = andConditions.length ? { $and: andConditions } : {};
|
|
72
|
+
const [result, total] = yield Promise.all([
|
|
73
|
+
skiptest_model_1.Skiptest
|
|
74
|
+
.find(whereConditions)
|
|
75
|
+
.skip(skip)
|
|
76
|
+
.limit(limit)
|
|
77
|
+
.sort({ [sortBy]: sortOrder }),
|
|
78
|
+
skiptest_model_1.Skiptest.countDocuments(whereConditions),
|
|
79
|
+
]);
|
|
80
|
+
return {
|
|
81
|
+
meta: {
|
|
82
|
+
page,
|
|
83
|
+
limit,
|
|
84
|
+
total,
|
|
85
|
+
totalPages: Math.ceil(total / limit),
|
|
86
|
+
},
|
|
87
|
+
data: result,
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
const getSingleSkiptest = (id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
|
+
if (!mongoose_1.Types.ObjectId.isValid(id)) {
|
|
92
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.BAD_REQUEST, 'Invalid Skiptest ID');
|
|
93
|
+
}
|
|
94
|
+
const result = yield skiptest_model_1.Skiptest.findById(id);
|
|
95
|
+
if (!result) {
|
|
96
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.NOT_FOUND, 'Requested skiptest not found, please try again with valid id');
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
});
|
|
100
|
+
const updateSkiptest = (id, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
+
if (!mongoose_1.Types.ObjectId.isValid(id)) {
|
|
102
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.BAD_REQUEST, 'Invalid Skiptest ID');
|
|
103
|
+
}
|
|
104
|
+
const result = yield skiptest_model_1.Skiptest.findByIdAndUpdate(new mongoose_1.Types.ObjectId(id), { $set: payload }, {
|
|
105
|
+
new: true,
|
|
106
|
+
runValidators: true,
|
|
107
|
+
});
|
|
108
|
+
if (!result) {
|
|
109
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.NOT_FOUND, 'Requested skiptest not found, please try again with valid id');
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
});
|
|
113
|
+
const deleteSkiptest = (id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
|
+
if (!mongoose_1.Types.ObjectId.isValid(id)) {
|
|
115
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.BAD_REQUEST, 'Invalid Skiptest ID');
|
|
116
|
+
}
|
|
117
|
+
const result = yield skiptest_model_1.Skiptest.findByIdAndDelete(id);
|
|
118
|
+
if (!result) {
|
|
119
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.NOT_FOUND, 'Something went wrong while deleting skiptest, please try again with valid id.');
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
});
|
|
123
|
+
exports.SkiptestServices = {
|
|
124
|
+
createSkiptest,
|
|
125
|
+
getAllSkiptests,
|
|
126
|
+
getSingleSkiptest,
|
|
127
|
+
updateSkiptest,
|
|
128
|
+
deleteSkiptest,
|
|
129
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SkiptestValidations = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.SkiptestValidations = {
|
|
6
|
+
create: zod_1.z.object({
|
|
7
|
+
name: zod_1.z.string(),
|
|
8
|
+
}),
|
|
9
|
+
update: zod_1.z.object({
|
|
10
|
+
name: zod_1.z.string().optional(),
|
|
11
|
+
}),
|
|
12
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSetEqual = exports.testmoduleSearchableFields = exports.testmoduleFilterables = void 0;
|
|
4
|
+
// Filterable fields for Testmodule
|
|
5
|
+
exports.testmoduleFilterables = ['name', 'email'];
|
|
6
|
+
// Searchable fields for Testmodule
|
|
7
|
+
exports.testmoduleSearchableFields = ['name', 'email'];
|
|
8
|
+
// Helper function for set comparison
|
|
9
|
+
const isSetEqual = (setA, setB) => {
|
|
10
|
+
if (setA.size !== setB.size)
|
|
11
|
+
return false;
|
|
12
|
+
for (const item of setA) {
|
|
13
|
+
if (!setB.has(item))
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
};
|
|
18
|
+
exports.isSetEqual = isSetEqual;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.TestmoduleController = void 0;
|
|
16
|
+
const testmodule_service_1 = require("./testmodule.service");
|
|
17
|
+
const catchAsync_1 = __importDefault(require("../../../shared/catchAsync"));
|
|
18
|
+
const sendResponse_1 = __importDefault(require("../../../shared/sendResponse"));
|
|
19
|
+
const http_status_codes_1 = require("http-status-codes");
|
|
20
|
+
const pick_1 = __importDefault(require("../../../shared/pick"));
|
|
21
|
+
const testmodule_constants_1 = require("./testmodule.constants");
|
|
22
|
+
const pagination_1 = require("../../../interfaces/pagination");
|
|
23
|
+
const createTestmodule = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const testmoduleData = req.body;
|
|
25
|
+
const result = yield testmodule_service_1.TestmoduleServices.createTestmodule(req.user, testmoduleData);
|
|
26
|
+
(0, sendResponse_1.default)(res, {
|
|
27
|
+
statusCode: http_status_codes_1.StatusCodes.CREATED,
|
|
28
|
+
success: true,
|
|
29
|
+
message: 'Testmodule created successfully',
|
|
30
|
+
data: result,
|
|
31
|
+
});
|
|
32
|
+
}));
|
|
33
|
+
const updateTestmodule = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
const { id } = req.params;
|
|
35
|
+
const testmoduleData = req.body;
|
|
36
|
+
const result = yield testmodule_service_1.TestmoduleServices.updateTestmodule(id, testmoduleData);
|
|
37
|
+
(0, sendResponse_1.default)(res, {
|
|
38
|
+
statusCode: http_status_codes_1.StatusCodes.OK,
|
|
39
|
+
success: true,
|
|
40
|
+
message: 'Testmodule updated successfully',
|
|
41
|
+
data: result,
|
|
42
|
+
});
|
|
43
|
+
}));
|
|
44
|
+
const getSingleTestmodule = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
const { id } = req.params;
|
|
46
|
+
const result = yield testmodule_service_1.TestmoduleServices.getSingleTestmodule(id);
|
|
47
|
+
(0, sendResponse_1.default)(res, {
|
|
48
|
+
statusCode: http_status_codes_1.StatusCodes.OK,
|
|
49
|
+
success: true,
|
|
50
|
+
message: 'Testmodule retrieved successfully',
|
|
51
|
+
data: result,
|
|
52
|
+
});
|
|
53
|
+
}));
|
|
54
|
+
const getAllTestmodules = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
const filterables = (0, pick_1.default)(req.query, testmodule_constants_1.testmoduleFilterables);
|
|
56
|
+
const pagination = (0, pick_1.default)(req.query, pagination_1.paginationFields);
|
|
57
|
+
const result = yield testmodule_service_1.TestmoduleServices.getAllTestmodules(req.user, filterables, pagination);
|
|
58
|
+
(0, sendResponse_1.default)(res, {
|
|
59
|
+
statusCode: http_status_codes_1.StatusCodes.OK,
|
|
60
|
+
success: true,
|
|
61
|
+
message: 'Testmodules retrieved successfully',
|
|
62
|
+
data: result,
|
|
63
|
+
});
|
|
64
|
+
}));
|
|
65
|
+
const deleteTestmodule = (0, catchAsync_1.default)((req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
const { id } = req.params;
|
|
67
|
+
const result = yield testmodule_service_1.TestmoduleServices.deleteTestmodule(id);
|
|
68
|
+
(0, sendResponse_1.default)(res, {
|
|
69
|
+
statusCode: http_status_codes_1.StatusCodes.OK,
|
|
70
|
+
success: true,
|
|
71
|
+
message: 'Testmodule deleted successfully',
|
|
72
|
+
data: result,
|
|
73
|
+
});
|
|
74
|
+
}));
|
|
75
|
+
exports.TestmoduleController = {
|
|
76
|
+
createTestmodule,
|
|
77
|
+
updateTestmodule,
|
|
78
|
+
getSingleTestmodule,
|
|
79
|
+
getAllTestmodules,
|
|
80
|
+
deleteTestmodule,
|
|
81
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Testmodule = void 0;
|
|
4
|
+
const mongoose_1 = require("mongoose");
|
|
5
|
+
const testmoduleSchema = new mongoose_1.Schema({
|
|
6
|
+
name: { type: String },
|
|
7
|
+
email: { type: String },
|
|
8
|
+
}, {
|
|
9
|
+
timestamps: true
|
|
10
|
+
});
|
|
11
|
+
exports.Testmodule = (0, mongoose_1.model)('Testmodule', testmoduleSchema);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TestmoduleRoutes = void 0;
|
|
7
|
+
const express_1 = __importDefault(require("express"));
|
|
8
|
+
const testmodule_controller_1 = require("./testmodule.controller");
|
|
9
|
+
const testmodule_validation_1 = require("./testmodule.validation");
|
|
10
|
+
const validateRequest_1 = __importDefault(require("../../middleware/validateRequest"));
|
|
11
|
+
const auth_1 = __importDefault(require("../../middleware/auth"));
|
|
12
|
+
const user_1 = require("../../../enum/user");
|
|
13
|
+
const router = express_1.default.Router();
|
|
14
|
+
router.get('/', (0, auth_1.default)(user_1.USER_ROLES.SUPER_ADMIN, user_1.USER_ROLES.ADMIN), testmodule_controller_1.TestmoduleController.getAllTestmodules);
|
|
15
|
+
router.get('/:id', (0, auth_1.default)(user_1.USER_ROLES.SUPER_ADMIN, user_1.USER_ROLES.ADMIN), testmodule_controller_1.TestmoduleController.getSingleTestmodule);
|
|
16
|
+
router.post('/', (0, auth_1.default)(user_1.USER_ROLES.SUPER_ADMIN, user_1.USER_ROLES.ADMIN), (0, validateRequest_1.default)(testmodule_validation_1.TestmoduleValidations.createTestmoduleZodSchema), testmodule_controller_1.TestmoduleController.createTestmodule);
|
|
17
|
+
router.patch('/:id', (0, auth_1.default)(user_1.USER_ROLES.SUPER_ADMIN, user_1.USER_ROLES.ADMIN), (0, validateRequest_1.default)(testmodule_validation_1.TestmoduleValidations.updateTestmoduleZodSchema), testmodule_controller_1.TestmoduleController.updateTestmodule);
|
|
18
|
+
router.delete('/:id', (0, auth_1.default)(user_1.USER_ROLES.SUPER_ADMIN, user_1.USER_ROLES.ADMIN), testmodule_controller_1.TestmoduleController.deleteTestmodule);
|
|
19
|
+
exports.TestmoduleRoutes = router;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.TestmoduleServices = void 0;
|
|
27
|
+
const http_status_codes_1 = require("http-status-codes");
|
|
28
|
+
const ApiError_1 = __importDefault(require("../../../errors/ApiError"));
|
|
29
|
+
const testmodule_model_1 = require("./testmodule.model");
|
|
30
|
+
const paginationHelper_1 = require("../../../helpers/paginationHelper");
|
|
31
|
+
const testmodule_constants_1 = require("./testmodule.constants");
|
|
32
|
+
const mongoose_1 = require("mongoose");
|
|
33
|
+
const createTestmodule = (user, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
try {
|
|
35
|
+
const result = yield testmodule_model_1.Testmodule.create(payload);
|
|
36
|
+
if (!result) {
|
|
37
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.BAD_REQUEST, 'Failed to create Testmodule, please try again with valid data.');
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (error.code === 11000) {
|
|
43
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.CONFLICT, 'Duplicate entry found');
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
const getAllTestmodules = (user, filterables, pagination) => __awaiter(void 0, void 0, void 0, function* () {
|
|
49
|
+
const { searchTerm } = filterables, filterData = __rest(filterables, ["searchTerm"]);
|
|
50
|
+
const { page, skip, limit, sortBy, sortOrder } = paginationHelper_1.paginationHelper.calculatePagination(pagination);
|
|
51
|
+
const andConditions = [];
|
|
52
|
+
// Search functionality
|
|
53
|
+
if (searchTerm) {
|
|
54
|
+
andConditions.push({
|
|
55
|
+
$or: testmodule_constants_1.testmoduleSearchableFields.map((field) => ({
|
|
56
|
+
[field]: {
|
|
57
|
+
$regex: searchTerm,
|
|
58
|
+
$options: 'i',
|
|
59
|
+
},
|
|
60
|
+
})),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
// Filter functionality
|
|
64
|
+
if (Object.keys(filterData).length) {
|
|
65
|
+
andConditions.push({
|
|
66
|
+
$and: Object.entries(filterData).map(([key, value]) => ({
|
|
67
|
+
[key]: value,
|
|
68
|
+
})),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const whereConditions = andConditions.length ? { $and: andConditions } : {};
|
|
72
|
+
const [result, total] = yield Promise.all([
|
|
73
|
+
testmodule_model_1.Testmodule
|
|
74
|
+
.find(whereConditions)
|
|
75
|
+
.skip(skip)
|
|
76
|
+
.limit(limit)
|
|
77
|
+
.sort({ [sortBy]: sortOrder }),
|
|
78
|
+
testmodule_model_1.Testmodule.countDocuments(whereConditions),
|
|
79
|
+
]);
|
|
80
|
+
return {
|
|
81
|
+
meta: {
|
|
82
|
+
page,
|
|
83
|
+
limit,
|
|
84
|
+
total,
|
|
85
|
+
totalPages: Math.ceil(total / limit),
|
|
86
|
+
},
|
|
87
|
+
data: result,
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
const getSingleTestmodule = (id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
|
+
if (!mongoose_1.Types.ObjectId.isValid(id)) {
|
|
92
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.BAD_REQUEST, 'Invalid Testmodule ID');
|
|
93
|
+
}
|
|
94
|
+
const result = yield testmodule_model_1.Testmodule.findById(id);
|
|
95
|
+
if (!result) {
|
|
96
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.NOT_FOUND, 'Requested testmodule not found, please try again with valid id');
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
});
|
|
100
|
+
const updateTestmodule = (id, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
+
if (!mongoose_1.Types.ObjectId.isValid(id)) {
|
|
102
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.BAD_REQUEST, 'Invalid Testmodule ID');
|
|
103
|
+
}
|
|
104
|
+
const result = yield testmodule_model_1.Testmodule.findByIdAndUpdate(new mongoose_1.Types.ObjectId(id), { $set: payload }, {
|
|
105
|
+
new: true,
|
|
106
|
+
runValidators: true,
|
|
107
|
+
});
|
|
108
|
+
if (!result) {
|
|
109
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.NOT_FOUND, 'Requested testmodule not found, please try again with valid id');
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
});
|
|
113
|
+
const deleteTestmodule = (id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
|
+
if (!mongoose_1.Types.ObjectId.isValid(id)) {
|
|
115
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.BAD_REQUEST, 'Invalid Testmodule ID');
|
|
116
|
+
}
|
|
117
|
+
const result = yield testmodule_model_1.Testmodule.findByIdAndDelete(id);
|
|
118
|
+
if (!result) {
|
|
119
|
+
throw new ApiError_1.default(http_status_codes_1.StatusCodes.NOT_FOUND, 'Something went wrong while deleting testmodule, please try again with valid id.');
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
});
|
|
123
|
+
exports.TestmoduleServices = {
|
|
124
|
+
createTestmodule,
|
|
125
|
+
getAllTestmodules,
|
|
126
|
+
getSingleTestmodule,
|
|
127
|
+
updateTestmodule,
|
|
128
|
+
deleteTestmodule,
|
|
129
|
+
};
|