Skip to content

Commit eec00a2

Browse files
committed
fix the const error
1 parent 6aa2a8a commit eec00a2

19 files changed

Lines changed: 96 additions & 87 deletions

File tree

backend/src/constants/httpStatusCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export enum HttpStatusCode {
33
CREATED = 201,
44

55
BAD_REQUEST = 400,
6-
UNAUTH0RIZED = 401,
6+
UNAUTHORIZED = 401,
77
FORBIDDEN = 403,
88
NOT_FOUND = 404,
99
CONFLICT = 409,

backend/src/constants/messages/successMessages.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export const SuccessMessages = {
5050
USER_FETCHED: "User fetched successfully",
5151
REVIEW_CREATED: "Review created successfully",
5252
REVIEWS_FETCHED: "Reviews fetched successfully",
53+
REVIEW_UPDATED: "Review updated successfully",
54+
REVIEW_DELETED: "Review deleted successfully",
5355

5456
EMAIL_UPDATE_OTP_SENT: (email: string, minutes: number) => `Verification OTP sent to ${email}. Expires in ${minutes} minutes`,
5557
EMAIL_UPDATE_OTP_RESENT: (email: string, minutes: number) => `Verification OTP resent to ${email}. Expires in ${minutes} minutes`,
@@ -67,4 +69,9 @@ export const SuccessMessages = {
6769
NOTIFICATION_MARKED_READ: "Notification marked as read",
6870
ALL_NOTIFICATIONS_MARKED_READ: "All notifications marked as read",
6971
NOTIFICATION_DELETED: "Notification deleted",
72+
73+
REPORT_SUBMITTED: "Report submitted successfully",
74+
REPORTS_FETCHED: "Reports fetched successfully",
75+
REPORT_STATUS_UPDATED: "Report status updated successfully",
76+
MODERATION_ACTION_TAKEN: (action: string) => `Action '${action}' taken successfully`,
7077
};

backend/src/middleware/auth.middleware.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ export const authMiddleware = async (
2020
const authHeader = req.headers.authorization;
2121
if (!authHeader || !authHeader.startsWith("Bearer ")) {
2222

23-
throw new AppError("Access denied. No token provided.", HttpStatusCode.UNAUTH0RIZED);
23+
throw new AppError("Access denied. No token provided.", HttpStatusCode.UNAUTHORIZED);
2424
}
2525

2626
const token = authHeader.split(" ")[1];
2727
const decoded = verifyAccessToken(token);
2828
const user = await UserModel.findById(decoded.userId).select("isBlocked");
2929
if (!user) {
30-
throw new AppError("User not found", HttpStatusCode.UNAUTH0RIZED);
30+
throw new AppError("User not found", HttpStatusCode.UNAUTHORIZED);
3131
}
3232
if (user.isBlocked) {
3333
throw new AppError("Your account has been blocked", HttpStatusCode.FORBIDDEN);
@@ -41,7 +41,7 @@ export const authMiddleware = async (
4141
next(error);
4242
return;
4343
}
44-
next(new AppError("Invalid or expired token", HttpStatusCode.UNAUTH0RIZED));
44+
next(new AppError("Invalid or expired token", HttpStatusCode.UNAUTHORIZED));
4545
}
4646
};
4747

backend/src/modules/assignment/controller/assignment.controller.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class AssignmentController implements IAssignmentController {
2929
const status = req.query.status as string;
3030

3131
if (!userId) {
32-
throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTH0RIZED);
32+
throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTHORIZED);
3333
}
3434

3535
const provider = await this._serviceProviderService.getProviderByUserId(userId);
@@ -55,7 +55,7 @@ export class AssignmentController implements IAssignmentController {
5555
const freelancerId = assignment?.freelancerId?._id ? assignment.freelancerId._id.toString() : assignment?.freelancerId?.toString();
5656

5757
if (!assignment || !provider || freelancerId !== provider._id.toString()) {
58-
throw new AppError(ErrorMessages.ASSIGNMENT_NOT_FOUND, HttpStatusCode.UNAUTH0RIZED);
58+
throw new AppError(ErrorMessages.ASSIGNMENT_NOT_FOUND, HttpStatusCode.UNAUTHORIZED);
5959
}
6060

6161
const jobId = assignment.jobId?._id ? assignment.jobId._id.toString() : assignment.jobId.toString();
@@ -141,7 +141,7 @@ export class AssignmentController implements IAssignmentController {
141141

142142
const updated = await this._assignmentService.cancelByProvider(id, provider._id.toString(), notes);
143143

144-
ApiResponse.sendSuccess(res, await mapAssignmentToResponseDTO(updated), 'Assignment cancelled successfully by provider');
144+
ApiResponse.sendSuccess(res, await mapAssignmentToResponseDTO(updated), SuccessMessages.ASSIGNMENT_CANCELLED_PROVIDER);
145145
} catch (error) {
146146
next(error);
147147
}
@@ -155,7 +155,7 @@ export class AssignmentController implements IAssignmentController {
155155

156156
const updated = await this._assignmentService.cancelByClient(id, userId as string, notes);
157157

158-
ApiResponse.sendSuccess(res, await mapAssignmentToResponseDTO(updated), 'Assignment cancelled successfully by client');
158+
ApiResponse.sendSuccess(res, await mapAssignmentToResponseDTO(updated), SuccessMessages.ASSIGNMENT_CANCELLED_CLIENT);
159159
} catch (error) {
160160
next(error);
161161
}
@@ -168,7 +168,7 @@ export class AssignmentController implements IAssignmentController {
168168
const { notes, evidence } = req.body;
169169
const updated = await this._assignmentService.reportAbsence(id, userId as string, notes, evidence);
170170

171-
ApiResponse.sendSuccess(res, await mapAssignmentToResponseDTO(updated), 'Absence reported successfully');
171+
ApiResponse.sendSuccess(res, await mapAssignmentToResponseDTO(updated), SuccessMessages.ABSENCE_REPORTED);
172172
} catch (error) {
173173
next(error);
174174
}
@@ -179,7 +179,7 @@ export class AssignmentController implements IAssignmentController {
179179
const userId = req.user?.userId;
180180
const id = req.params.id as string;
181181
const updated = await this._assignmentService.markAsPaidByCash(id, userId as string);
182-
ApiResponse.sendSuccess(res, await mapAssignmentToResponseDTO(updated), 'Payment marked as paid by cash');
182+
ApiResponse.sendSuccess(res, await mapAssignmentToResponseDTO(updated), SuccessMessages.PAYMENT_MARKED_CASH);
183183
} catch (error) {
184184
next(error);
185185
}
@@ -193,7 +193,7 @@ export class AssignmentController implements IAssignmentController {
193193
if (!provider) throw new AppError('Provider not found', HttpStatusCode.NOT_FOUND);
194194

195195
const updated = await this._assignmentService.confirmPayment(id, provider._id.toString());
196-
ApiResponse.sendSuccess(res, await mapAssignmentToResponseDTO(updated), 'Payment confirmed');
196+
ApiResponse.sendSuccess(res, await mapAssignmentToResponseDTO(updated), SuccessMessages.PAYMENT_CONFIRMED);
197197
} catch (error) {
198198
next(error);
199199
}
@@ -208,7 +208,7 @@ export class AssignmentController implements IAssignmentController {
208208
if (!provider) throw new AppError('Provider not found', HttpStatusCode.NOT_FOUND);
209209

210210
const updated = await this._assignmentService.providerMarkAsPaid(id, provider._id.toString());
211-
ApiResponse.sendSuccess(res, await mapAssignmentToResponseDTO(updated), 'Payment marked as received by hand');
211+
ApiResponse.sendSuccess(res, await mapAssignmentToResponseDTO(updated), SuccessMessages.PAYMENT_MARKED_RECEIVED_HAND);
212212
} catch (error) {
213213
next(error);
214214
}
@@ -222,7 +222,7 @@ export class AssignmentController implements IAssignmentController {
222222
if (!provider) throw new AppError('Provider not found', HttpStatusCode.NOT_FOUND);
223223

224224
const updated = await this._assignmentService.rejectPayment(id, provider._id.toString());
225-
ApiResponse.sendSuccess(res, await mapAssignmentToResponseDTO(updated), 'Payment confirmation rejected');
225+
ApiResponse.sendSuccess(res, await mapAssignmentToResponseDTO(updated), SuccessMessages.PAYMENT_CONFIRMATION_REJECTED);
226226
} catch (error) {
227227
next(error);
228228
}

backend/src/modules/auth/controllers/auth.controller.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export class AuthController implements IAuthController {
209209
try {
210210
const userId = req.user?.userId;
211211
if (!userId) {
212-
throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTH0RIZED);
212+
throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTHORIZED);
213213
}
214214
const result = await this._authService.getProfile(userId);
215215
res.status(HttpStatusCode.OK).json({
@@ -230,7 +230,7 @@ export class AuthController implements IAuthController {
230230
try {
231231
const userId = req.user?.userId;
232232
if (!userId) {
233-
throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTH0RIZED);
233+
throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTHORIZED);
234234
}
235235
const { name, number, profileImage } = req.body;
236236
const result = await this._authService.updateProfile(userId, { name, number, profileImage });
@@ -252,7 +252,7 @@ export class AuthController implements IAuthController {
252252
try {
253253
const userId = req.user?.userId;
254254
if (!userId) {
255-
throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTH0RIZED);
255+
throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTHORIZED);
256256
}
257257
const { currentPassword, newPassword } = req.body;
258258
await this._authService.changePassword(userId, { currentPassword, newPassword });
@@ -273,7 +273,7 @@ export class AuthController implements IAuthController {
273273
try {
274274
const userId = req.user?.userId;
275275
if (!userId) {
276-
throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTH0RIZED);
276+
throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTHORIZED);
277277
}
278278
const { newEmail } = req.body;
279279
const result = await this._authService.sendEmailUpdateOtp(userId, { newEmail });
@@ -291,7 +291,7 @@ export class AuthController implements IAuthController {
291291
try {
292292
const userId = req.user?.userId;
293293
if (!userId) {
294-
throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTH0RIZED);
294+
throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTHORIZED);
295295
}
296296
const { newEmail, otp } = req.body;
297297
const result = await this._authService.verifyEmailUpdate(userId, { newEmail, otp });
@@ -309,7 +309,7 @@ export class AuthController implements IAuthController {
309309
try {
310310
const userId = req.user?.userId;
311311
if (!userId) {
312-
throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTH0RIZED);
312+
throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTHORIZED);
313313
}
314314
const { newEmail } = req.body;
315315
const result = await this._authService.resendEmailUpdateOtp(userId, { newEmail });

backend/src/modules/auth/services/auth.service.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export class AuthService implements IAuthService {
143143
public async login(input: ILoginInput): Promise<ILoginResponse> {
144144
const user = await this._authRepository.findByEmailWithPassword(input.email);
145145
if (!user) {
146-
throw new AppError(ErrorMessages.INVALID_CREDENTIALS, HttpStatusCode.UNAUTH0RIZED);
146+
throw new AppError(ErrorMessages.INVALID_CREDENTIALS, HttpStatusCode.UNAUTHORIZED);
147147
}
148148

149149
if (user.isBlocked) {
@@ -154,7 +154,7 @@ export class AuthService implements IAuthService {
154154
if (user.authProvider === 'google') {
155155
throw new AppError("This account was created using Google Sign-In. Please continue with Google or set a password.", HttpStatusCode.BAD_REQUEST);
156156
}
157-
throw new AppError(ErrorMessages.INVALID_CREDENTIALS, HttpStatusCode.UNAUTH0RIZED);
157+
throw new AppError(ErrorMessages.INVALID_CREDENTIALS, HttpStatusCode.UNAUTHORIZED);
158158
}
159159

160160
const isPasswordValid = await bcrypt.compare(input.password, user.hashedPassword);
@@ -190,12 +190,12 @@ export class AuthService implements IAuthService {
190190
try {
191191
decoded = verifyRefreshToken(token);
192192
} catch {
193-
throw new AppError(ErrorMessages.INVALID_OR_EXPIRED_TOKEN, HttpStatusCode.UNAUTH0RIZED);
193+
throw new AppError(ErrorMessages.INVALID_OR_EXPIRED_TOKEN, HttpStatusCode.UNAUTHORIZED);
194194
}
195195

196196
const user = await this._authRepository.findById(decoded.userId);
197197
if (!user) {
198-
throw new AppError(ErrorMessages.USER_NOT_FOUND, HttpStatusCode.UNAUTH0RIZED);
198+
throw new AppError(ErrorMessages.USER_NOT_FOUND, HttpStatusCode.UNAUTHORIZED);
199199
}
200200

201201
if (user.isBlocked) {
@@ -220,7 +220,7 @@ export class AuthService implements IAuthService {
220220
};
221221
}
222222
public async adminLogin(input: ILoginInput): Promise<IAdminLoginResponse> {
223-
const genericError = new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTH0RIZED);
223+
const genericError = new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTHORIZED);
224224

225225
const user = await this._authRepository.findByEmailWithPassword(input.email);
226226
if (!user) {
@@ -265,11 +265,11 @@ export class AuthService implements IAuthService {
265265
try {
266266
const varify = verifyRefreshToken(token);
267267
if (!varify) {
268-
throw new AppError(ErrorMessages.INVALID_OR_EXPIRED_TOKEN, HttpStatusCode.UNAUTH0RIZED);
268+
throw new AppError(ErrorMessages.INVALID_OR_EXPIRED_TOKEN, HttpStatusCode.UNAUTHORIZED);
269269
}
270270
await this._otpRepository.deleteByRefreshToken(token);
271271
} catch {
272-
throw new AppError(ErrorMessages.INVALID_OR_EXPIRED_TOKEN, HttpStatusCode.UNAUTH0RIZED);
272+
throw new AppError(ErrorMessages.INVALID_OR_EXPIRED_TOKEN, HttpStatusCode.UNAUTHORIZED);
273273
}
274274

275275
return {

backend/src/modules/finance/controllers/invoice.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class InvoiceController implements IInvoiceController {
1717
public getMyInvoices = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
1818
try {
1919
const userId = req.user?.userId;
20-
if (!userId) throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTH0RIZED);
20+
if (!userId) throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTHORIZED);
2121

2222
const { page = 1, limit = 10, role } = req.query;
2323

backend/src/modules/finance/controllers/payment.controller.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class PaymentController implements IPaymentController {
2525
try {
2626
const { workHistoryId } = req.params as { workHistoryId: string };
2727
const clientId = req.user?.userId;
28-
if (!clientId) throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTH0RIZED);
28+
if (!clientId) throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTHORIZED);
2929

3030
const result = await this._paymentService.markAsPaidCash(workHistoryId, clientId);
3131
res.status(result.success ? HttpStatusCode.OK : HttpStatusCode.BAD_REQUEST).json(result);
@@ -38,7 +38,7 @@ export class PaymentController implements IPaymentController {
3838
try {
3939
const { workHistoryId } = req.params as { workHistoryId: string };
4040
const userId = req.user?.userId;
41-
if (!userId) throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTH0RIZED);
41+
if (!userId) throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTHORIZED);
4242

4343
const provider = await this._serviceProviderService.getProviderByUserId(userId);
4444
if (!provider) throw new AppError(ErrorMessages.PROVIDER_NOT_FOUND, HttpStatusCode.NOT_FOUND);
@@ -54,7 +54,7 @@ export class PaymentController implements IPaymentController {
5454
try {
5555
const { workHistoryId } = req.params as { workHistoryId: string };
5656
const userId = req.user?.userId;
57-
if (!userId) throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTH0RIZED);
57+
if (!userId) throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTHORIZED);
5858

5959
const provider = await this._serviceProviderService.getProviderByUserId(userId);
6060
if (!provider) throw new AppError(ErrorMessages.PROVIDER_NOT_FOUND, HttpStatusCode.NOT_FOUND);
@@ -88,7 +88,7 @@ export class PaymentController implements IPaymentController {
8888
public getProviderWorkHistory = async (req: Request, res: Response, next: NextFunction): Promise<void> => {
8989
try {
9090
const userId = req.user?.userId;
91-
if (!userId) throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTH0RIZED);
91+
if (!userId) throw new AppError(ErrorMessages.UNAUTHORIZED, HttpStatusCode.UNAUTHORIZED);
9292

9393
const { page = 1, limit = 10, status } = req.query;
9494

@@ -133,20 +133,20 @@ export class PaymentController implements IPaymentController {
133133
try {
134134
const {
135135
workHistoryId,
136-
razorpay_order_id,
137-
razorpay_payment_id,
138-
razorpay_signature
136+
razorpay_order_id: razorpayOrderId,
137+
razorpay_payment_id: razorpayPaymentId,
138+
razorpay_signature: razorpaySignature
139139
} = req.body;
140140

141-
if (!workHistoryId || !razorpay_order_id || !razorpay_payment_id || !razorpay_signature) {
141+
if (!workHistoryId || !razorpayOrderId || !razorpayPaymentId || !razorpaySignature) {
142142
throw new AppError(ErrorMessages.RAZORPAY_DETAILS_REQUIRED, HttpStatusCode.BAD_REQUEST);
143143
}
144144

145145
const result = await this._paymentService.verifyRazorpayPayment(
146146
workHistoryId,
147-
razorpay_order_id,
148-
razorpay_payment_id,
149-
razorpay_signature
147+
razorpayOrderId,
148+
razorpayPaymentId,
149+
razorpaySignature
150150
);
151151

152152
res.status(HttpStatusCode.OK).json(result);
@@ -171,20 +171,20 @@ export class PaymentController implements IPaymentController {
171171
try {
172172
const {
173173
jobId,
174-
razorpay_order_id,
175-
razorpay_payment_id,
176-
razorpay_signature
174+
razorpay_order_id: razorpayOrderId,
175+
razorpay_payment_id: razorpayPaymentId,
176+
razorpay_signature: razorpaySignature
177177
} = req.body;
178178

179-
if (!jobId || !razorpay_order_id || !razorpay_payment_id || !razorpay_signature) {
179+
if (!jobId || !razorpayOrderId || !razorpayPaymentId || !razorpaySignature) {
180180
throw new AppError(ErrorMessages.RAZORPAY_DETAILS_REQUIRED, HttpStatusCode.BAD_REQUEST);
181181
}
182182

183183
const result = await this._paymentService.verifyJobRazorpayPayment(
184184
jobId,
185-
razorpay_order_id,
186-
razorpay_payment_id,
187-
razorpay_signature
185+
razorpayOrderId,
186+
razorpayPaymentId,
187+
razorpaySignature
188188
);
189189

190190
res.status(HttpStatusCode.OK).json(result);

0 commit comments

Comments
 (0)