Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#187419063- Build Rest End Points for ROLE #19

Merged
merged 2 commits into from
Apr 30, 2024

Conversation

Tuyisenge2
Copy link
Collaborator

What does this PR do?

Admin should be able to assign various users to various roles

Description of Task to be completed?

having following endpoints working
-POST api/v1/roles
-POST api/v1/users/:userId/roles
-PATCH api/v1/roles/:id
-DELETE api/v1/roles/:id

How should this be manually tested?

  • After cloning the repo, cd into it and first RUN npm migrate and then RUN npm run dev
    Using Postman test every endpoint above with this header:
    key: Content-Type value: application/json
    To test authentication, add this to the header: Get TOKEN from login endpoint
    key: Authorization value: JWT TOKEN

@Tuyisenge2 Tuyisenge2 added the WIP label Apr 24, 2024
@Tuyisenge2 Tuyisenge2 changed the title #187419063- Build Rest End Points for Resources #187419063- Build Rest End Points for ROLE Apr 24, 2024
@@ -0,0 +1,185 @@
import app from "../app";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

@Tuyisenge2 Tuyisenge2 force-pushed the feat-Roles-Permission-187419063 branch 19 times, most recently from 7fdce1f to 4089153 Compare April 29, 2024 15:03
@@ -0,0 +1,98 @@
import { Request, Response } from "express";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

"use strict";
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: Unexpected token up

import { DataTypes, Model, Optional, UUIDV4 } from "sequelize";
import { sequelizeConnection } from "../config/db.config";

import { DataTypes, Model, Optional, Sequelize, UUIDV4 } from "sequelize";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

responses,
},
},
"/roles/{id}": {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

await queryInterface.bulkInsert(
"users",
[
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 3 locations. Consider refactoring.

createdAt: new Date(),
updatedAt: new Date(),
},
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 3 locations. Consider refactoring.

createdAt: new Date(),
updatedAt: new Date(),
},
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 3 locations. Consider refactoring.

import { NextFunction, Request, Response } from "express";
import { HttpException } from "../utils/http.exception";

export const roleNameValid = async (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

@Tuyisenge2 Tuyisenge2 force-pushed the feat-Roles-Permission-187419063 branch from 4089153 to 23c9398 Compare April 29, 2024 21:48
@@ -0,0 +1,10 @@
import { Sequelize } from "sequelize";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

@@ -0,0 +1,35 @@
import { DataTypes, Sequelize, Model, Optional, UUIDV4 } from "sequelize";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'


/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: Unexpected token up

@@ -0,0 +1,58 @@
const bcrypt = require("bcrypt");
const hashPassword = async (password) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: Unexpected token =>

@@ -0,0 +1,100 @@
import { responses } from "../responses";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

@@ -0,0 +1,64 @@
import {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

@@ -0,0 +1,18 @@
import {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

@@ -0,0 +1,25 @@
import Joi from "joi";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: 'import' and 'export' may appear only with 'sourceType: module'

expect(body.message).toStrictEqual("Please Login Again");
});

it("it should return Invalid token and return 403 ", async () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

}
};

export const roleIdValidations = async (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

} from "../mock/static";
const role = database_models["role"];
jest.setTimeout(30000);
function logErrors(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

UserId?: JwtPayload;
}

function logErrors(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 2 locations. Consider refactoring.

responses,
},
},
"/users/{userId}/roles": {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

@Tuyisenge2 Tuyisenge2 force-pushed the feat-Roles-Permission-187419063 branch from 23c9398 to 382514f Compare April 30, 2024 13:09

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing error: Unexpected token up

UserId?: JwtPayload;
}

function logErrors(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identical blocks of code found in 3 locations. Consider refactoring.

// await deleteTableData(database_models.role, "roles");
});

it("it should register a user and return 201", async () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

expect(body.message).toStrictEqual("Role assigned successfully!");
});

it("it should return please login and return 401 ", async () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

expect(body.status).toStrictEqual(409);
});

it("it should return role not found and return 404 ", async () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

expect(body.message).toStrictEqual("role not found");
});

it("it should assign user to role and return 201 ", async () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar blocks of code found in 2 locations. Consider refactoring.

Copy link

codeclimate bot commented Apr 30, 2024

Code Climate has analyzed commit 382514f and detected 19 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 1
Duplication 18

The test coverage on the diff in this pull request is 91.1% (60% is the threshold).

This pull request will bring the total coverage in the repository to 91.2% (0.0% change).

View more on Code Climate.

@leandreAlly leandreAlly merged commit 76408a9 into develop Apr 30, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants