Skip to content

Commit cdbbbe1

Browse files
committed
refactor: Convert remaining validation and service files to ES modules
- Convert custom.validation.js, auth.validation.js, user.validation.js to ES modules - Convert about.service.js, terms.service.js, privacy.service.js, email.service.js to ES modules - Add missing dependencies: he and moment to package.json - All src files now use ES modules (import/export) - Verified no require() or module.exports remain in src directory
1 parent db1f8ef commit cdbbbe1

8 files changed

Lines changed: 45 additions & 55 deletions

File tree

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@
5656
"stripe": "^14.19.0",
5757
"nodemailer": "^6.9.7",
5858
"firebase-admin": "^12.0.0",
59+
"he": "^1.2.0",
5960
"bull": "^4.12.0",
6061
"ioredis": "^5.3.2",
62+
"moment": "^2.30.1",
6163
"multer": "^1.4.5-lts.1",
6264
"swagger-jsdoc": "^6.2.8",
6365
"swagger-ui-express": "^5.0.0",

src/services/about.service.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const httpStatus = require('http-status');
2-
const { About } = require('../models');
3-
const ApiError = require('../utils/ApiError');
4-
const he = require('he');
1+
import httpStatus from 'http-status';
2+
import { About } from '../models/index.js';
3+
import ApiError from '../utils/ApiError.js';
4+
import he from 'he';
55

66

77
const createAbout = async (aboutBody) => {
@@ -28,7 +28,4 @@ const queryAbouts = async () => {
2828
return abouts;
2929
};
3030

31-
module.exports = {
32-
createAbout,
33-
queryAbouts
34-
};
31+
export { createAbout, queryAbouts };

src/services/email.service.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const nodemailer = require("nodemailer");
2-
const config = require("../config/config");
3-
const logger = require("../config/logger");
1+
import nodemailer from 'nodemailer';
2+
import config from '../config/config.js';
3+
import logger from '../config/logger.js';
44

55
const transport = nodemailer.createTransport(config.email.smtp);
66
/* istanbul ignore next */
@@ -67,7 +67,7 @@ If you did not create an account, then ignore this email.`;
6767
await sendEmail(to, subject, text);
6868
};
6969

70-
module.exports = {
70+
export {
7171
transport,
7272
sendEmail,
7373
sendResetPasswordEmail,

src/services/privacy.service.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const httpStatus = require('http-status');
2-
const { Privacy } = require('../models');
3-
const ApiError = require('../utils/ApiError');
4-
const he = require('he');
1+
import httpStatus from 'http-status';
2+
import { Privacy } from '../models/index.js';
3+
import ApiError from '../utils/ApiError.js';
4+
import he from 'he';
55

66

77
const createPrivacy = async (privacyBody) => {
@@ -28,7 +28,4 @@ const queryPrivacy = async () => {
2828
};
2929

3030

31-
module.exports = {
32-
createPrivacy,
33-
queryPrivacy
34-
};
31+
export { createPrivacy, queryPrivacy };

src/services/terms.service.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const httpStatus = require("http-status");
2-
const { Terms } = require("../models");
3-
const ApiError = require("../utils/ApiError");
4-
const he = require("he");
1+
import httpStatus from 'http-status';
2+
import { Terms } from '../models/index.js';
3+
import ApiError from '../utils/ApiError.js';
4+
import he from 'he';
55

66
const createTerms = async (termsBody) => {
77
termsBody.content = he.decode(termsBody.content);
@@ -24,7 +24,4 @@ const queryTerms = async () => {
2424
return terms;
2525
};
2626

27-
module.exports = {
28-
createTerms,
29-
queryTerms,
30-
};
27+
export { createTerms, queryTerms };

src/validations/auth.validation.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const Joi = require("joi");
2-
const { password } = require("./custom.validation");
1+
import Joi from 'joi';
2+
import { password } from './custom.validation.js';
33

44
const register = {
55
body: Joi.object().keys({
@@ -72,7 +72,7 @@ const verifyOTP = {
7272
otpCode: Joi.string().required(),
7373
}),
7474
}
75-
module.exports = {
75+
export {
7676
register,
7777
login,
7878
logout,
@@ -81,5 +81,5 @@ module.exports = {
8181
resetPassword,
8282
verifyEmail,
8383
deleteMe,
84-
changePassword
84+
changePassword,
8585
};
Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
const objectId = (value, helpers) => {
2-
if (!value.match(/^[0-9a-fA-F]{24}$/)) {
3-
return helpers.message('"{{#label}}" must be a valid mongo id');
4-
}
5-
return value;
6-
};
7-
8-
const password = (value, helpers) => {
9-
if (value.length < 8) {
10-
return helpers.message('password must be at least 8 characters');
11-
}
12-
if (!value.match(/\d/) || !value.match(/[a-zA-Z]/)) {
13-
return helpers.message('password must contain at least 1 letter and 1 number');
14-
}
15-
return value;
16-
};
17-
18-
module.exports = {
19-
objectId,
20-
password,
21-
};
2+
if (!value.match(/^[0-9a-fA-F]{24}$/)) {
3+
return helpers.message('"{{#label}}" must be a valid mongo id');
4+
}
5+
return value;
6+
};
7+
8+
const password = (value, helpers) => {
9+
if (value.length < 8) {
10+
return helpers.message('password must be at least 8 characters');
11+
}
12+
if (!value.match(/\d/) || !value.match(/[a-zA-Z]/)) {
13+
return helpers.message('password must contain at least 1 letter and 1 number');
14+
}
15+
return value;
16+
};
17+
18+
export { objectId, password };

src/validations/user.validation.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const Joi = require("joi");
2-
const { password, objectId } = require("./custom.validation");
1+
import Joi from 'joi';
2+
import { password, objectId } from './custom.validation.js';
33

44
const createUser = {
55
body: Joi.object().keys({
@@ -55,7 +55,7 @@ const getHome = {
5555

5656
};
5757

58-
module.exports = {
58+
export {
5959
getHome,
6060
createUser,
6161
getUsers,

0 commit comments

Comments
 (0)