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

#187419064 A seller should be able to CRUD products #21

Merged
merged 1 commit into from
May 1, 2024

Conversation

cyusasnave
Copy link
Collaborator

What does this PR do?

As a Seller, I should be able to CRUD items for sale, such that the stock can be seen by any requesting client.

Description of Task to be completed?

  • A seller should be able to add product
  • A every should be able to read the products
  • A seller should be able to update the product
  • A seller should be able to delete the product

Endpoints:

POST /api/v1/products ---- (or adding/creating items)
GET /api/v1/products ----- (for getting all products/items)
GET /api/v1/products/:id ------ (for getting single product/items)
PATCH /api/v1/products/:id ----- (for updating a single product/items)
DELETE /api/v1/products/:id ----- (for removing a product in seller’s collection)

How should this be manually tested?

  • Clone the repo nd cd into it
  • Go to this branch
  • Run npm install
  • Check the .env.example and update your .env file ( Added environment variables for CLOUDINARY )
  • Run npm run dev to start the application
  • Test every endpoint using postman or Use swagger docs on /api/v1/docs

Pivotracker Id

#187419064

src/controllers/categoryController.ts Show resolved Hide resolved
src/controllers/productController.ts Show resolved Hide resolved
@@ -0,0 +1,55 @@
import { DataTypes, Model, 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'

@@ -0,0 +1,108 @@
import { DataTypes, Model, 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'

src/documention/product/index.ts Show resolved Hide resolved
src/helpers/cloudinary.ts Show resolved Hide resolved
src/helpers/upload.ts Outdated Show resolved Hide resolved
src/middlewares/multer.ts Show resolved Hide resolved
@cyusasnave cyusasnave force-pushed the feat-CRUD-product-187419064 branch from f285177 to ed47bd2 Compare April 24, 2024 20:31
@cyusasnave cyusasnave force-pushed the feat-CRUD-product-187419064 branch from ed47bd2 to 92b7e73 Compare April 25, 2024 20:27
@cyusasnave cyusasnave force-pushed the feat-CRUD-product-187419064 branch 2 times, most recently from 683843d to 496e857 Compare April 25, 2024 21:36
src/documention/category/index.ts Show resolved Hide resolved
expect(body.message).toStrictEqual("Product not found!");
});

it("should return 400 when product is invalid", 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.product).toBeDefined();
});

it("should return 404 when product doesn't exist", 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("Product deleted successfully!");
});

it("should return 404 when the product doesn't exist", 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.

import { validate as isValidUUID } from "uuid";

const add_category = async (req: Request, res: Response) => {
try {
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 8 locations. Consider refactoring.

@cyusasnave cyusasnave requested review from YvetteNyibuka and removed request for GarrixA April 26, 2024 07:33
Copy link
Collaborator

@YvetteNyibuka YvetteNyibuka left a comment

Choose a reason for hiding this comment

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

Good Job @cyusasnave.

@cyusasnave cyusasnave force-pushed the feat-CRUD-product-187419064 branch from 496e857 to 2846324 Compare April 27, 2024 07:31
expect(body.message).toStrictEqual(" Only seller can perform this action!");
});

it("should successfully login a user and return 200", 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.product).toBeDefined();
});

it("should delete a product and return 200", 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.category).toBeDefined();
});

it("should return 400 when a user provided an invalid id", 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("No field provided to update!");
});

it("should return 400 when you try to update unexisting category", 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.

};

const read_all_categories = async (_req: Request, res: Response) => {
try {
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 8 locations. Consider refactoring.

@cyusasnave cyusasnave force-pushed the feat-CRUD-product-187419064 branch from 2846324 to 568536f Compare April 29, 2024 09:10

/** @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

@@ -1,32 +1,37 @@
import { DataTypes, Model, Optional, UUIDV4 } from "sequelize";
import { sequelizeConnection } from "../config/db.config";
import { DataTypes, Model, 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'

@@ -0,0 +1,5 @@
export type emailAttribute = {
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'

@@ -1,5 +1,24 @@
import path from "path";
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,66 @@
import { Optional } 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,3 @@
export type InfoAttribute = {
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,10 @@
export type UserInt = {
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,9 @@
import { Request } 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'

@@ -0,0 +1,18 @@
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'

@@ -0,0 +1,58 @@
/* eslint-disable no-shadow */
import { CreateOptions, FindOptions, UpdateOptions } 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'

@@ -1,3 +1,5 @@
import { 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'

@cyusasnave cyusasnave force-pushed the feat-CRUD-product-187419064 branch from 568536f to 2e314ef Compare April 29, 2024 09:13
@@ -0,0 +1,20 @@
import express 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'

@@ -0,0 +1,42 @@
import express 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'

@@ -1,3 +1,7 @@
import database_models from "../database/config/db.config";
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,32 @@
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'

await deleteTableData(database_models.User, "users");
});

it("should successfully login a user and return 200", 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.

if (!condition) {
throw new Error("Condition is required for update operation");
}
const result = await (
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.

}

if (method === "create") {
const result = await (
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.

);
});

it("should return 400 if product id is invalid", 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("You provided Invalid ID!");
});

it("should return 404 if product doesn't exist", 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.

@cyusasnave cyusasnave force-pushed the feat-CRUD-product-187419064 branch from 2e314ef to 8be3be9 Compare April 30, 2024 21:48
@@ -0,0 +1,155 @@
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'

@@ -1,24 +1,31 @@
import { DataTypes, Model, Optional, Sequelize, UUIDV4 } from "sequelize";
import { DataTypes, Model, 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'

email: string;
resetToken: string;
}
import { DataTypes, Model, 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'

@@ -1,10 +1,6 @@
import { DataTypes, Sequelize, Model, Optional, UUIDV4 } from "sequelize";
import { DataTypes, Sequelize, Model, 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 = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
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

@@ -1,4 +1,9 @@
import { GOOGLE_CALLBACK_URL, PORT } from "../utils/keys";
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,312 @@
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'

await deleteTableData(database_models.User, "users");
});

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 4 locations. Consider refactoring.

);
});

it("should fetch all catgories and return 200", 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.

);
});

it("should fetch all products and return 200", 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.

);
});

it("should return 409 when category already exist", 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.

category_id = body.data.id;
});

it("should create a new category 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 8be3be9 and detected 59 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 7
Duplication 52

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

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

View more on Code Climate.

@leandreAlly leandreAlly merged commit ec7e9d9 into develop May 1, 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