diff --git a/backend/.eslintrc.json b/backend/.eslintrc.json index 9edbbb1..aa015fa 100644 --- a/backend/.eslintrc.json +++ b/backend/.eslintrc.json @@ -17,6 +17,7 @@ }, "plugins": ["@typescript-eslint", "prettier"], "rules": { + "@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/no-unused-vars": [ "error", { "argsIgnorePattern": "_" } diff --git a/backend/coverage/lcov-report/AuthServices/RefreshTokenService.ts.html b/backend/coverage/lcov-report/AuthServices/RefreshTokenService.ts.html index 1c5845d..32112c2 100644 --- a/backend/coverage/lcov-report/AuthServices/RefreshTokenService.ts.html +++ b/backend/coverage/lcov-report/AuthServices/RefreshTokenService.ts.html @@ -187,7 +187,7 @@
diff --git a/backend/coverage/lcov-report/AuthServices/index.html b/backend/coverage/lcov-report/AuthServices/index.html index 104244f..d7dadca 100644 --- a/backend/coverage/lcov-report/AuthServices/index.html +++ b/backend/coverage/lcov-report/AuthServices/index.html @@ -95,7 +95,7 @@ diff --git a/backend/coverage/lcov-report/ContactServices/CreateContactService.ts.html b/backend/coverage/lcov-report/ContactServices/CreateContactService.ts.html index 3b7a777..dc74396 100644 --- a/backend/coverage/lcov-report/ContactServices/CreateContactService.ts.html +++ b/backend/coverage/lcov-report/ContactServices/CreateContactService.ts.html @@ -202,7 +202,7 @@ diff --git a/backend/coverage/lcov-report/ContactServices/DeleteContactService.ts.html b/backend/coverage/lcov-report/ContactServices/DeleteContactService.ts.html index f50f9ce..6095cc2 100644 --- a/backend/coverage/lcov-report/ContactServices/DeleteContactService.ts.html +++ b/backend/coverage/lcov-report/ContactServices/DeleteContactService.ts.html @@ -112,7 +112,7 @@ diff --git a/backend/coverage/lcov-report/ContactServices/ListContactsService.ts.html b/backend/coverage/lcov-report/ContactServices/ListContactsService.ts.html index 21dbff4..7a12096 100644 --- a/backend/coverage/lcov-report/ContactServices/ListContactsService.ts.html +++ b/backend/coverage/lcov-report/ContactServices/ListContactsService.ts.html @@ -214,7 +214,7 @@ diff --git a/backend/coverage/lcov-report/ContactServices/ShowContactService.ts.html b/backend/coverage/lcov-report/ContactServices/ShowContactService.ts.html index 4c94b72..0a4e69e 100644 --- a/backend/coverage/lcov-report/ContactServices/ShowContactService.ts.html +++ b/backend/coverage/lcov-report/ContactServices/ShowContactService.ts.html @@ -106,7 +106,7 @@ diff --git a/backend/coverage/lcov-report/ContactServices/UpdateContactService.ts.html b/backend/coverage/lcov-report/ContactServices/UpdateContactService.ts.html index 4976727..1c4d8fb 100644 --- a/backend/coverage/lcov-report/ContactServices/UpdateContactService.ts.html +++ b/backend/coverage/lcov-report/ContactServices/UpdateContactService.ts.html @@ -274,7 +274,7 @@ diff --git a/backend/coverage/lcov-report/ContactServices/index.html b/backend/coverage/lcov-report/ContactServices/index.html index b9b178b..2fd966c 100644 --- a/backend/coverage/lcov-report/ContactServices/index.html +++ b/backend/coverage/lcov-report/ContactServices/index.html @@ -155,7 +155,7 @@ diff --git a/backend/coverage/lcov-report/MessageServices/CreateMessageService.ts.html b/backend/coverage/lcov-report/MessageServices/CreateMessageService.ts.html index c26b978..8e5a7cc 100644 --- a/backend/coverage/lcov-report/MessageServices/CreateMessageService.ts.html +++ b/backend/coverage/lcov-report/MessageServices/CreateMessageService.ts.html @@ -187,7 +187,7 @@ diff --git a/backend/coverage/lcov-report/MessageServices/ListMessagesService.ts.html b/backend/coverage/lcov-report/MessageServices/ListMessagesService.ts.html index e91f094..119f887 100644 --- a/backend/coverage/lcov-report/MessageServices/ListMessagesService.ts.html +++ b/backend/coverage/lcov-report/MessageServices/ListMessagesService.ts.html @@ -250,7 +250,7 @@ diff --git a/backend/coverage/lcov-report/MessageServices/index.html b/backend/coverage/lcov-report/MessageServices/index.html index 7815105..18ac61a 100644 --- a/backend/coverage/lcov-report/MessageServices/index.html +++ b/backend/coverage/lcov-report/MessageServices/index.html @@ -110,7 +110,7 @@ diff --git a/backend/coverage/lcov-report/SettingServices/ListSettingsService.ts.html b/backend/coverage/lcov-report/SettingServices/ListSettingsService.ts.html index 0b2effd..0b2e482 100644 --- a/backend/coverage/lcov-report/SettingServices/ListSettingsService.ts.html +++ b/backend/coverage/lcov-report/SettingServices/ListSettingsService.ts.html @@ -91,7 +91,7 @@ diff --git a/backend/coverage/lcov-report/SettingServices/UpdateSettingService.ts.html b/backend/coverage/lcov-report/SettingServices/UpdateSettingService.ts.html index 7333233..deb7211 100644 --- a/backend/coverage/lcov-report/SettingServices/UpdateSettingService.ts.html +++ b/backend/coverage/lcov-report/SettingServices/UpdateSettingService.ts.html @@ -142,7 +142,7 @@ diff --git a/backend/coverage/lcov-report/SettingServices/index.html b/backend/coverage/lcov-report/SettingServices/index.html index 3974171..e487142 100644 --- a/backend/coverage/lcov-report/SettingServices/index.html +++ b/backend/coverage/lcov-report/SettingServices/index.html @@ -110,7 +110,7 @@ diff --git a/backend/coverage/lcov-report/TicketServices/CreateTicketService.ts.html b/backend/coverage/lcov-report/TicketServices/CreateTicketService.ts.html index 5664852..df5eb10 100644 --- a/backend/coverage/lcov-report/TicketServices/CreateTicketService.ts.html +++ b/backend/coverage/lcov-report/TicketServices/CreateTicketService.ts.html @@ -184,7 +184,7 @@ diff --git a/backend/coverage/lcov-report/TicketServices/DeleteTicketService.ts.html b/backend/coverage/lcov-report/TicketServices/DeleteTicketService.ts.html index 8f93a7d..194be02 100644 --- a/backend/coverage/lcov-report/TicketServices/DeleteTicketService.ts.html +++ b/backend/coverage/lcov-report/TicketServices/DeleteTicketService.ts.html @@ -118,7 +118,7 @@ diff --git a/backend/coverage/lcov-report/TicketServices/ListTicketsService.ts.html b/backend/coverage/lcov-report/TicketServices/ListTicketsService.ts.html index 6634ab9..7b88672 100644 --- a/backend/coverage/lcov-report/TicketServices/ListTicketsService.ts.html +++ b/backend/coverage/lcov-report/TicketServices/ListTicketsService.ts.html @@ -496,7 +496,7 @@ diff --git a/backend/coverage/lcov-report/TicketServices/ShowTicketService.ts.html b/backend/coverage/lcov-report/TicketServices/ShowTicketService.ts.html index 90682db..d3be7c0 100644 --- a/backend/coverage/lcov-report/TicketServices/ShowTicketService.ts.html +++ b/backend/coverage/lcov-report/TicketServices/ShowTicketService.ts.html @@ -154,7 +154,7 @@ diff --git a/backend/coverage/lcov-report/TicketServices/UpdateTicketService.ts.html b/backend/coverage/lcov-report/TicketServices/UpdateTicketService.ts.html index 7a19f4a..7ce5caa 100644 --- a/backend/coverage/lcov-report/TicketServices/UpdateTicketService.ts.html +++ b/backend/coverage/lcov-report/TicketServices/UpdateTicketService.ts.html @@ -250,7 +250,7 @@ diff --git a/backend/coverage/lcov-report/TicketServices/index.html b/backend/coverage/lcov-report/TicketServices/index.html index e72a4f4..06cdc44 100644 --- a/backend/coverage/lcov-report/TicketServices/index.html +++ b/backend/coverage/lcov-report/TicketServices/index.html @@ -155,7 +155,7 @@ diff --git a/backend/coverage/lcov-report/UserServices/AuthUserSerice.ts.html b/backend/coverage/lcov-report/UserServices/AuthUserSerice.ts.html index a4153ef..d516254 100644 --- a/backend/coverage/lcov-report/UserServices/AuthUserSerice.ts.html +++ b/backend/coverage/lcov-report/UserServices/AuthUserSerice.ts.html @@ -199,7 +199,7 @@ diff --git a/backend/coverage/lcov-report/UserServices/CreateUserService.ts.html b/backend/coverage/lcov-report/UserServices/CreateUserService.ts.html index 07d89be..d709a9d 100644 --- a/backend/coverage/lcov-report/UserServices/CreateUserService.ts.html +++ b/backend/coverage/lcov-report/UserServices/CreateUserService.ts.html @@ -23,30 +23,30 @@| 1 2 @@ -124,149 +124,140 @@ 65 66 67 -68 -69 -70 -71 | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | import * as Yup from "yup"; - -import AppError from "../../errors/AppError"; -import User from "../../models/User"; - -interface Request { - email: string; - password: string; - name: string; - profile?: string; -} - -interface Response { - email: string; - name: string; - id: number; - profile: string; -} - -const CreateUserService = async ({ - email, - password, - name, - profile = "admin" -}: Request): Promise<Response> => { - const schema = Yup.object().shape({ - name: Yup.string().required().min(2), - email: Yup.string() - .email() - .required() - .test( - "Check-email", - "An user with this email already exists.", - async value => { - if (value) { - const emailExists = await User.findOne({ - where: { email: value } - }); - return !emailExists; - } - return false; - } - ), - password: Yup.string().required().min(5) - }); - - try { - await schema.validate({ email, password, name }); - } catch (err) { - throw new AppError(err.message); - } - - const user = await User.create({ - email, - password, - name, - profile - }); - - const serializedUser = { - id: user.id, - name: user.name, - email: user.email, - profile: user.profile - }; - - return serializedUser; -}; - -export default CreateUserService; +68 | 1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +1x +5x +5x +5x +5x +5x +5x +5x +5x +5x +5x +5x +5x +5x +5x +5x +5x +5x +4x +4x +5x +5x +5x +5x +5x +5x +5x +1x +1x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +3x +1x +1x + | import * as Yup from "yup";
+
+import AppError from "../../errors/AppError";
+import User from "../../models/User";
+
+interface Request {
+ email: string;
+ password: string;
+ name: string;
+ profile?: string;
+}
+
+interface Response {
+ email: string;
+ name: string;
+ id: number;
+ profile: string;
+}
+
+const CreateUserService = async ({
+ email,
+ password,
+ name,
+ profile = "admin"
+}: Request): Promise<Response> => {
+ const schema = Yup.object().shape({
+ name: Yup.string().required().min(2),
+ email: Yup.string()
+ .email()
+ .required()
+ .test(
+ "Check-email",
+ "An user with this email already exists.",
+ async value => {
+ const emailExists = await User.findOne({
+ where: { email: value! }
+ });
+ return !emailExists;
+ }
+ ),
+ password: Yup.string().required().min(5)
+ });
+
+ try {
+ await schema.validate({ email, password, name });
+ } catch (err) {
+ throw new AppError(err.message);
+ }
+
+ const user = await User.create({
+ email,
+ password,
+ name,
+ profile
+ });
+
+ const serializedUser = {
+ id: user.id,
+ name: user.name,
+ email: user.email,
+ profile: user.profile
+ };
+
+ return serializedUser;
+};
+
+export default CreateUserService;
|