Skip to content

Commit

Permalink
[Finishes #187584924] Seller Create/Add a product (#48)
Browse files Browse the repository at this point in the history
* [Delivers #187584924] Seller Create/Add a product

* updated ReaderMe file

* Rebased on develop
  • Loading branch information
AimePazzo authored Jun 6, 2024
1 parent 5a3356d commit dad2ece
Show file tree
Hide file tree
Showing 34 changed files with 1,967 additions and 684 deletions.
25 changes: 15 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ Our e-commerce web application server, developed by Team Ninjas, facilitates smo
- Verification Email Endpoint
- Resend verification Endpoint
- Login Endpoint
- Admin get users Endpoint
- Admin get user Endpoint
- login vie google Endpoint
- Admin Update Status Endpoint
- Admin Update Role Endpoint
- Admin get users Endpoint
- Admin get user Endpoint
- Logout Endpoint
- Update User Profile Endpoint
- Get User Profile Endpoint
- Login Via google account
- Seller create shop Endpoint
- Seller create product Endpoint

## TABLE OF API ENDPOINTS SPECIFICATION AND DESCRIPTION

Expand All @@ -47,14 +49,17 @@ Our e-commerce web application server, developed by Team Ninjas, facilitates smo
| 3 | GET | /api/auth/verify-email/:token | 200 OK | public | Verifying email |
| 4 | POST | /api/auth/send-verify-email | 200 OK | public | Resend verification email |
| 5 | POST | /api/auth/login | 200 OK | public | Login with Email and Password |
| 6 | GET | /api/user/admin-get-users | 200 OK | private | Admin get all users Endpoint |
| 7 | GET | /api/user/admin-get-user/:id | 200 OK | private | Admin get user Endpoint |
| 8 | PUT | /api/user/admin-update-user-status/:id | 200 OK | private | Admin Update Status Endpoint |
| 9 | PUT | /api/user/admin-update-role/:id | 200 OK | private | Admin Update Role Endpoint |
| 6 | PUT | /admin-update-user-status/:id | 200 OK | private | Admin Update Status Endpoint |
| 7 | PUT | /admin-update-role/:id | 200 OK | private | Admin Update role Endpoint |
| 8 | GET | /api/user/admin-get-users | 200 OK | private | Admin get all users Endpoint |
| 9 | GET | /api/user/admin-get-users/:id | 200 OK | private | Admin get one user Endpoint |
| 10 | POST | /api/auth/logout | 200 OK | private | Logout user |
| 11 | PUT | /api/user/user-update-profile | 200 OK | private | Update User Profile Endpoint |
| 11 | GET | /api/user/user-get-profile | 200 OK | private | Get User Profile Endpoint |
| 12 | GET | /api/auth/google | 200 OK | public | Login Via google account |
| 11 | POST | /api/shop/create-shop | 201 OK | private | Create shop for products |
| 13 | POST | /api/shop/create-product | 201 OK | private | create product in shop |
| 14 | PUT | /api/user/user-update-profile | 200 OK | private | Update User Profile Endpoint |
| 15 | GET | /api/user/user-get-profile | 200 OK | private | Get User Profile Endpoint |
| 15 | POST | /api/auth/google | 200 OK | public | Login Via google account |

## INSTALLATION

1. Clone the repository:
Expand Down
32 changes: 26 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"createAllSeeders": "tsc && npx sequelize db:seed:all",
"deleteAllTables": "tsc && npx sequelize db:migrate:undo:all",
"deleteAllSeeders": "tsc && npx sequelize db:seed:undo:all",
"start": "ts-node-dev src/index.ts",
"dev": "ts-node-dev src/index.ts",
"start": "src/index.ts",
"dev": "nodemon src/index.ts",
"test": "cross-env NODE_ENV=test npm run deleteAllTables && cross-env NODE_ENV=test npm run createAllTables && cross-env NODE_ENV=test npm run createAllSeeders && nyc cross-env NODE_ENV=test mocha --require ts-node/register 'src/**/*.spec.ts' --timeout 600000 --exit",
"test-local": "cross-env NODE_ENV=development npm run deleteAllTables && cross-env NODE_ENV=development npm run createAllTables && cross-env NODE_ENV=development npm run createAllSeeders && nyc cross-env NODE_ENV=development mocha --require ts-node/register 'src/**/*.spec.ts' --timeout 600000 --exit",
"coveralls": "nyc --reporter=lcov --reporter=text-lcov npm test | coveralls",
Expand All @@ -36,6 +36,7 @@
"src/index.spec.ts",
"src/databases/**/*.*",
"src/modules/**/test/*.spec.ts",
"src/types/*.*",
"src/services/googleAuth.ts"
],
"reporter": [
Expand Down Expand Up @@ -92,7 +93,8 @@
"swagger-ui-express": "^5.0.0",
"ts-node": "^10.9.2",
"ts-node-dev": "^2.0.0",
"typescript": "^5.4.5"
"typescript": "^5.4.5",
"uuid": "^9.0.1"
},
"devDependencies": {
"@types/bcrypt": "^5.0.2",
Expand All @@ -107,6 +109,7 @@
"@types/sequelize": "^4.28.20",
"@types/swagger-jsdoc": "^6.0.4",
"@types/swagger-ui-express": "^4.1.6",
"@types/uuid": "^9.0.8",
"@typescript-eslint/eslint-plugin": "^7.10.0",
"@typescript-eslint/parser": "^7.10.0",
"eslint": "^8.57.0",
Expand Down
13 changes: 5 additions & 8 deletions src/databases/migrations/20240520180022-create-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export default {

await queryInterface.createTable("users", {
id: {
type: DataTypes.INTEGER,
type: DataTypes.UUID,
allowNull: false,
autoIncrement: true,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
firstName: {
Expand Down Expand Up @@ -96,12 +96,9 @@ export default {
},

down: async (queryInterface: QueryInterface) => {
// Drop the users table
await queryInterface.dropTable("users");

// Drop the enum type if it exists
await queryInterface.sequelize.query(`
DROP TYPE IF EXISTS "enum_users_gender";
`);
await queryInterface.sequelize.query(
"DROP TYPE IF EXISTS \"enum_users_gender\";"
);
}
};
22 changes: 14 additions & 8 deletions src/databases/migrations/20240523180022-create-sessions.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import { QueryInterface, DataTypes } from "sequelize";

export default {
up: async (queryInterface: QueryInterface) => {
await queryInterface.createTable("sessions", {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
type: DataTypes.UUID,
allowNull: false,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
userId: {
type: new DataTypes.INTEGER,
allowNull: false
type: DataTypes.UUID,
allowNull: false,
references: {
model: "users",
key: "id"
},
onUpdate: "CASCADE",
onDelete: "CASCADE"
},
device: {
type: new DataTypes.STRING(280),
Expand All @@ -24,15 +32,13 @@ export default {
allowNull: true
},
createdAt: {
field: "createdAt",
type: DataTypes.DATE,
allowNull: false,
type: DataTypes.DATE,
defaultValue: DataTypes.NOW
},
updatedAt: {
field: "updatedAt",
type: DataTypes.DATE,
allowNull: false,
type: DataTypes.DATE,
defaultValue: DataTypes.NOW
}
});
Expand Down
46 changes: 46 additions & 0 deletions src/databases/migrations/20240601223523-create-shops.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { DataTypes, QueryInterface} from "sequelize";

export default {
up: async (queryInterface: QueryInterface, Sequelize: any) => {
await queryInterface.createTable("shops", {
id: {
allowNull: false,
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
name: {
allowNull: false,
type: DataTypes.STRING(128)
},
userId: {
allowNull: false,
type: DataTypes.UUID,
references: {
model: "users",
key: "id"
},
onDelete: "CASCADE"
},
description: {
type: DataTypes.STRING,
allowNull: true
},
createdAt: {
allowNull: false,
type: DataTypes.DATE,
defaultValue: Sequelize.literal("CURRENT_TIMESTAMP")
},
updatedAt: {
allowNull: false,
type: DataTypes.DATE,
defaultValue: Sequelize.literal("CURRENT_TIMESTAMP")
}
});
},

down: async (queryInterface: QueryInterface) => {
await queryInterface.dropTable("shops");
}
};
81 changes: 81 additions & 0 deletions src/databases/migrations/20240601223524-create-products.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { QueryInterface, DataTypes } from "sequelize";

export default {
up: async (queryInterface: QueryInterface, Sequelize: any) => {
await queryInterface.createTable("Products", {
id: {
allowNull: false,
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4
},
shopId: {
allowNull: false,
type: DataTypes.UUID,
references: {
model: "shops",
key: "id"
},
onDelete: "CASCADE"
},
name: {
allowNull: false,
type: DataTypes.STRING
},
description: {
type: DataTypes.STRING,
allowNull: true
},
price: {
allowNull: false,
type: DataTypes.DECIMAL(10, 2)
},
discount: {
type: DataTypes.STRING,
allowNull: true
},
category: {
allowNull: false,
type: DataTypes.STRING
},
expiryDate: {
type: DataTypes.DATE
},
expired: {
type: DataTypes.BOOLEAN,
defaultValue: false
},
bonus: {
type: DataTypes.STRING
},
images: {
type: DataTypes.ARRAY(DataTypes.STRING)
},
quantity: {
allowNull: false,
type: DataTypes.INTEGER,
defaultValue: 0
},
isAvailable: {
type: DataTypes.STRING(128),
allowNull: false,
defaultValue: "available"
},
createdAt: {
allowNull: false,
type: DataTypes.DATE,
defaultValue: Sequelize.literal("CURRENT_TIMESTAMP")
},
updatedAt: {
allowNull: false,
type: DataTypes.DATE,
defaultValue: Sequelize.literal("CURRENT_TIMESTAMP")
}
});
},

down: async (queryInterface: QueryInterface) => {
await queryInterface.dropTable("Products");
}
};
Loading

0 comments on commit dad2ece

Please sign in to comment.