-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
@@ -0,0 +1,55 @@ | |||
import { DataTypes, Model, Sequelize, UUIDV4 } from "sequelize"; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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'
f285177
to
ed47bd2
Compare
ed47bd2
to
92b7e73
Compare
683843d
to
496e857
Compare
expect(body.message).toStrictEqual("Product not found!"); | ||
}); | ||
|
||
it("should return 400 when product is invalid", async () => { |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good Job @cyusasnave.
496e857
to
2846324
Compare
src/__test__/category.test.ts
Outdated
expect(body.message).toStrictEqual(" Only seller can perform this action!"); | ||
}); | ||
|
||
it("should successfully login a user and return 200", async () => { |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
2846324
to
568536f
Compare
|
||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up(queryInterface, Sequelize) { |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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'
568536f
to
2e314ef
Compare
@@ -0,0 +1,20 @@ | |||
import express from "express"; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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/__test__/product.test.ts
Outdated
await deleteTableData(database_models.User, "users"); | ||
}); | ||
|
||
it("should successfully login a user and return 200", async () => { |
There was a problem hiding this comment.
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 ( |
There was a problem hiding this comment.
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 ( |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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.
2e314ef
to
8be3be9
Compare
@@ -0,0 +1,155 @@ | |||
import { Request, Response } from "express"; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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.
Code Climate has analyzed commit 8be3be9 and detected 59 issues on this pull request. Here's the issue category breakdown:
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. |
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?
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?
npm install
.env.example
and update your.env
file ( Added environment variables for CLOUDINARY )npm run dev
to start the application/api/v1/docs
Pivotracker Id
#187419064