purge string service
This commit is contained in:
1 parent
cc9850c975
commit
4957209307
16 files changed
+41
-1048
No files matched your search
@@ -1,10 +1,11 @@
|
||||
import { AppError } from "@/utils/AppError.js";
|
||||
|
||||
const SERVICE_NAME = "inviteModule";
|
||||
|
||||
class InviteModule {
|
||||
constructor({ InviteToken, crypto, stringService }) {
|
||||
constructor({ InviteToken, crypto }) {
|
||||
this.InviteToken = InviteToken;
|
||||
this.crypto = crypto;
|
||||
this.stringService = stringService;
|
||||
}
|
||||
|
||||
requestInviteToken = async (userData) => {
|
||||
@@ -27,7 +28,7 @@ class InviteModule {
|
||||
token,
|
||||
});
|
||||
if (invite === null) {
|
||||
throw new Error(this.stringService.authInviteNotFound);
|
||||
throw new AppError({ message: "Invite token not found", status: 404 });
|
||||
}
|
||||
return invite;
|
||||
} catch (error) {
|
||||
@@ -42,7 +43,7 @@ class InviteModule {
|
||||
token,
|
||||
});
|
||||
if (invite === null) {
|
||||
throw new Error(this.stringService.authInviteNotFound);
|
||||
throw new Error("Invite not found");
|
||||
}
|
||||
return invite;
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
const SERVICE_NAME = "recoveryModule";
|
||||
|
||||
class RecoveryModule {
|
||||
constructor({ User, RecoveryToken, crypto, stringService }) {
|
||||
constructor({ User, RecoveryToken, crypto }) {
|
||||
this.User = User;
|
||||
this.RecoveryToken = RecoveryToken;
|
||||
this.crypto = crypto;
|
||||
this.stringService = stringService;
|
||||
}
|
||||
|
||||
requestRecoveryToken = async (email) => {
|
||||
@@ -32,7 +31,7 @@ class RecoveryModule {
|
||||
if (recoveryToken !== null) {
|
||||
return recoveryToken;
|
||||
} else {
|
||||
throw new Error(this.stringService.dbTokenNotFound);
|
||||
throw new Error("Recovery token not found");
|
||||
}
|
||||
} catch (error) {
|
||||
error.service = SERVICE_NAME;
|
||||
@@ -50,7 +49,7 @@ class RecoveryModule {
|
||||
const user = await this.User.findOne({ email: recoveryToken.email });
|
||||
|
||||
if (user === null) {
|
||||
throw new Error(this.stringService.dbUserNotFound);
|
||||
throw new Error("User not found");
|
||||
}
|
||||
|
||||
const match = await user.comparePassword(newPassword);
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
const SERVICE_NAME = "statusPageModule";
|
||||
|
||||
class StatusPageModule {
|
||||
constructor({ StatusPage, NormalizeData, stringService, AppSettings }) {
|
||||
constructor({ StatusPage, NormalizeData, AppSettings }) {
|
||||
this.StatusPage = StatusPage;
|
||||
this.NormalizeData = NormalizeData;
|
||||
this.stringService = stringService;
|
||||
this.AppSettings = AppSettings;
|
||||
}
|
||||
|
||||
@@ -27,7 +26,7 @@ class StatusPageModule {
|
||||
if (error?.code === 11000) {
|
||||
// Handle duplicate URL errors
|
||||
error.status = 400;
|
||||
error.message = this.stringService.statusPageUrlNotUnique;
|
||||
error.message = "Status page URL must be unique";
|
||||
}
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "createStatusPage";
|
||||
@@ -87,7 +86,7 @@ class StatusPageModule {
|
||||
try {
|
||||
const preliminaryStatusPage = await this.StatusPage.findOne({ url });
|
||||
if (!preliminaryStatusPage) {
|
||||
const error = new Error(this.stringService.statusPageNotFound);
|
||||
const error = new Error("Status page not found");
|
||||
error.status = 404;
|
||||
throw error;
|
||||
}
|
||||
@@ -249,7 +248,7 @@ class StatusPageModule {
|
||||
},
|
||||
]);
|
||||
if (!statusPageQuery.length) {
|
||||
const error = new Error(this.stringService.statusPageNotFound);
|
||||
const error = new Error("Status page not found");
|
||||
error.status = 404;
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -2,12 +2,11 @@ const SERVICE_NAME = "userModule";
|
||||
const DUPLICATE_KEY_CODE = 11000; // MongoDB error code for duplicate key
|
||||
|
||||
class UserModule {
|
||||
constructor({ User, Team, GenerateAvatarImage, ParseBoolean, stringService }) {
|
||||
constructor({ User, Team, GenerateAvatarImage, ParseBoolean }) {
|
||||
this.User = User;
|
||||
this.Team = Team;
|
||||
this.GenerateAvatarImage = GenerateAvatarImage;
|
||||
this.ParseBoolean = ParseBoolean;
|
||||
this.stringService = stringService;
|
||||
}
|
||||
|
||||
checkSuperadmin = async () => {
|
||||
@@ -53,7 +52,7 @@ class UserModule {
|
||||
return await this.User.findOne({ _id: newUser._id }).select("-password").select("-profileImage"); // .select() doesn't work with create, need to save then find
|
||||
} catch (error) {
|
||||
if (error.code === DUPLICATE_KEY_CODE) {
|
||||
error.message = this.stringService.dbUserExists;
|
||||
error.message = "User already exists";
|
||||
}
|
||||
error.service = SERVICE_NAME;
|
||||
error.method = "insertUser";
|
||||
@@ -66,7 +65,7 @@ class UserModule {
|
||||
// We can strip the hash before returning the user
|
||||
const user = await this.User.findOne({ email: email }).select("-profileImage");
|
||||
if (!user) {
|
||||
throw new Error(this.stringService.dbUserNotFound);
|
||||
throw new Error("User not found");
|
||||
}
|
||||
return user;
|
||||
} catch (error) {
|
||||
@@ -117,7 +116,7 @@ class UserModule {
|
||||
try {
|
||||
const deletedUser = await this.User.findByIdAndDelete(userId);
|
||||
if (!deletedUser) {
|
||||
throw new Error(this.stringService.dbUserNotFound);
|
||||
throw new Error("User not found");
|
||||
}
|
||||
return deletedUser;
|
||||
} catch (error) {
|
||||
|
||||
Reference in new issue
Block a user