From 60d2b54c51631cbb4426e6b5897e2adf725f4b0b Mon Sep 17 00:00:00 2001 From: sevelinCA Date: Fri, 17 May 2024 15:26:24 +0200 Subject: [PATCH 01/24] add dotenv --- .env | 5 +++++ .gitignore | 3 +-- jest.config.js | 8 ++++---- src/database/config/config.js | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..87b7504 --- /dev/null +++ b/.env @@ -0,0 +1,5 @@ +PORT: 5000 +MODE: development +DATABASE_DEVELOPMENT_URL: postgres://ecommerce_crafters:SbURswsoV8KbisVverlrMFQ8SGusdp8a@dpg-cp0un1nsc6pc7382j630-a.oregon-postgres.render.com/ecommerce_crafters_data +DATABASE_TEST_URL: postgres://ecommerce_crafters:SbURswsoV8KbisVverlrMFQ8SGusdp8a@dpg-cp0un1nsc6pc7382j630-a.oregon-postgres.render.com/ecommerce_crafters_data +DATABASE_PRODUCTION_URL: postgres://ecommerce_crafters:SbURswsoV8KbisVverlrMFQ8SGusdp8a@dpg-cp0un1nsc6pc7382j630-a.oregon-postgres.render.com/ecommerce_crafters_data diff --git a/.gitignore b/.gitignore index 1c2b7f7..458115e 100644 --- a/.gitignore +++ b/.gitignore @@ -13,8 +13,7 @@ bin-release/ *.ipa *.apk -# Envirnoment variables -.env + # Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties` # should NOT be excluded as they contain compiler settings and other important # information for Eclipse / Flash Builder. diff --git a/jest.config.js b/jest.config.js index 7d48ba5..6f865d6 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,5 @@ module.exports = { - preset: 'ts-jest', - testEnvironment: 'node' - }; - \ No newline at end of file + preset: 'ts-jest', + testEnvironment: 'node', + setupFilesAfterEnv: ['./jest.config.js'] // Assuming the setup file is called jest.setup.js +}; diff --git a/src/database/config/config.js b/src/database/config/config.js index ca224f6..ed0267c 100644 --- a/src/database/config/config.js +++ b/src/database/config/config.js @@ -2,7 +2,7 @@ const dotenv = require('dotenv') dotenv.config() module.exports = { "development": { - "url": process.env.DATABASE_DEVELOPMENT_URL, + "url": process.env.DATABASE_TEST_URL, "dialect": "postgres", "dialectOptions": { "ssl": { From 091be427fcfe837dc4ad1fcf33661e8504cc6778 Mon Sep 17 00:00:00 2001 From: sevelinCA Date: Fri, 17 May 2024 16:26:35 +0200 Subject: [PATCH 02/24] fix js files --- tsconfig.json | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index 94d29b7..6919e94 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -44,8 +44,8 @@ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ /* JavaScript Support */ - // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ - // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ /* Emit */ @@ -83,7 +83,7 @@ /* Type Checking */ "strict": true, /* Enable all strict type-checking options. */ - "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + "noImplicitAny": false, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ @@ -105,5 +105,8 @@ /* Completeness */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ - } + }, + "exclude": [ + "jest.config.js" + ], } From 07de7549dc2648d5f5d6615f7b68eed774c25693 Mon Sep 17 00:00:00 2001 From: sevelinCA Date: Fri, 17 May 2024 17:53:25 +0200 Subject: [PATCH 03/24] add before and after --- src/__test__/user.test.ts | 9 ++++++++- src/index.ts | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/__test__/user.test.ts b/src/__test__/user.test.ts index 7161420..0856423 100644 --- a/src/__test__/user.test.ts +++ b/src/__test__/user.test.ts @@ -1,7 +1,14 @@ import request from 'supertest'; -import {app} from '..' +import {app,server} from '..' describe("Welcome endpoint",()=>{ + beforeAll((done) => { + done(); + }); + + afterAll((done) => { + server.close(done); + }); it('should return welcome message and status 200 ', async()=>{ const response = await request(app).get('/'); expect(response.status).toBe(200); diff --git a/src/index.ts b/src/index.ts index 3c5e12f..4dc28a3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,8 +20,8 @@ app.use("/api-docs", swaggerRoute); - app.listen(PORT, () => { + const server = app.listen(PORT, () => { console.log(`Server running on Port ${PORT}`); }); -export { app }; +export { app,server }; From c2eb4c2fb58535d593ab07d67c38219c804aabde Mon Sep 17 00:00:00 2001 From: berniceu <113672733+berniceu@users.noreply.github.com> Date: Mon, 13 May 2024 23:25:32 +0200 Subject: [PATCH 04/24] Create node.js.yml installs node dependencies, builds source code and runs tests for continuous integration --- .github/workflows/node.js.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/node.js.yml diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 0000000..ac5cd16 --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,27 @@ +# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs + +name: Code Crafters E-commerce CI + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: '20.x' + + - name: install dependencies + run: npm install + + - name: build + run: npm run build --if-present + + - name: run tests + run: npm run test From 851619cee77c4602cf314e1e24e208342d108ef7 Mon Sep 17 00:00:00 2001 From: HITAYEZU Jean Pierre Date: Mon, 13 May 2024 00:50:19 +0200 Subject: [PATCH 05/24] Readme file created --- LICENSE | 21 +++++++++++++ README.md | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b721604 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Ileriayo Adebiyi + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index e27f146..92f9516 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,87 @@ -# e-commerce-crafters-bn -Crafter's backend repo + +# e-commerce-crafters-bn :muscle: +This repository contains the backend application of an e-commerce website developed by Andela Team Crafters +[![GitHub](https://badgen.net/badge/icon/github?icon=github&label)](https://github.com) + +- Table of content + - [Project Overview](#project-overview) + - [Technology used](#technology-used) + - [Using the project](#using-the-project) + - [Prerequisites](#prerequisites) + - [Installation](#installation) + - [Contribution](#contribution) + - [Documentation](#documentation) + - [Deployed\_link:](#deployed_link) + - [Licensing](#licensing) +### 1. Project Overview + +In our project we developed an ecommerce application which is a platform where buyers and sellers meet to interact. Each Seller will be able to register, post their products, and fully manage their stock. Buyers will be able to see all the products on the platform, add and remove products to their shopping carts, and buy from any seller where they will be able to pay via the platform. + +### 2. Technology used + +* Node.js: ![Node.js](https://img.shields.io/badge/-Node.js-000000?style=flat&logo=node.js) + +* Express: ![Express.js](https://img.shields.io/badge/express.js-%23404d59.svg?logo=express&logoColor=%2361DAFB&style=for-the-badge) + +* Postgres Database: [![PostgreSQL](https://img.shields.io/badge/database-PostgreSQL-blue)](https://www.postgresql.org/) + +* Sequelize ORM: [![Sequelize](https://img.shields.io/badge/ORM-Sequelize-orange)](https://sequelize.org/) + +* Testing by Jest:[![Jest](https://img.shields.io/badge/testing-Jest-red)](https://jestjs.io/) + + +## 3.Using the project + + For those who are interested to use it locally,he/she is required the following: + +### * Prerequisites + +- Node.js +- Packages +- Postgres database +- Git + +### *Installation + +1. Clone the repository from github https://github.com/atlp-rwanda/e-commerce-crafters-bn.git +2. Run `npm install` to install all package dependencies +3. Copy the environment configuration: + `cp .env.example .env` + you can update the values of .env file with yours. +3. To run migrations into Postgres use the following command: + `npx sequelize-cli db:migrate` + `sequelize-cli`: This refers to the Sequelize Command Line Interface (CLI), which provides commands for interacting with Sequelize, including creating migrations, models, seeders, and running migrations. +4. To run seeders into Postgres use the following command: + `npx sequelize-cli db:seed:all` +5. Run the project using this command `npm start` +6. running test by `npm test` + +## 4.Contribution + +To contribute to this project: + +1. Clone the repository +2. Create your own branch to avoid direct pushing to main brach without creating pullrequest and get reviewed. + +- feature(ft): `git checkout -b ft-name-of-the-feature-bn-TrelloId` +- chore(ch): `git checkout -b ch-name-of-the-chore-bn-TrelloId ` +- bug(bd): `git checkout -b bg-name-of-the-bug-bn-TrelloId ` + + +1. Then you can commit any changes you made by: `git commit -m "your commit message"` +2. Push your changes to the branch you created `git push origin your-new-branch-name` +3. create a pull request and wait for review from other collabolators +### 5.Documentation +![Swagger Badge](https://img.shields.io/badge/Swagger-85EA2D?logo=swagger&logoColor=000&style=for-the-badge) +The following are steps to create your api documentation: +- Navigate to the location `src/docs`. +Create a `.yaml` file. +- Write your documentation in the file. + No need to set up Swagger-related things in `server.ts` again.
:warning: + You must know that YAML strictly follows indentation +### Deployed_link: +## 6.Licensing +[![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://github.com/Naereen/StrapDown.js/blob/master/LICENSE) +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for detail. + + From 313f61782f52e225a617c971824b0f8d81e58a9c Mon Sep 17 00:00:00 2001 From: HITAYEZU Jean Pierre Date: Tue, 14 May 2024 16:34:20 +0200 Subject: [PATCH 06/24] readme modified --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 92f9516..bdc0138 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ Create a `.yaml` file. - Write your documentation in the file. No need to set up Swagger-related things in `server.ts` again.
:warning: You must know that YAML strictly follows indentation -### Deployed_link: +### Deployed_link:https://e-commerce-crafters-bn.onrender.com/ ## 6.Licensing [![GitHub license](https://img.shields.io/github/license/Naereen/StrapDown.js.svg)](https://github.com/Naereen/StrapDown.js/blob/master/LICENSE) This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for detail. From 09d6015209599c412e705d82b98d17b7d401584f Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 21 May 2024 11:45:42 +0200 Subject: [PATCH 07/24] started working on seeders --- .../seeders/20240520152029-demo-user.js | 48 +++++++++++++++++++ .../seeders/20240520152858-demo-cart.js | 30 ++++++++++++ .../seeders/20240520153205-demo-vendor.js | 29 +++++++++++ .../seeders/20240520153801-demo-product.js | 47 ++++++++++++++++++ 4 files changed, 154 insertions(+) create mode 100644 src/database/seeders/20240520152029-demo-user.js create mode 100644 src/database/seeders/20240520152858-demo-cart.js create mode 100644 src/database/seeders/20240520153205-demo-vendor.js create mode 100644 src/database/seeders/20240520153801-demo-product.js diff --git a/src/database/seeders/20240520152029-demo-user.js b/src/database/seeders/20240520152029-demo-user.js new file mode 100644 index 0000000..277ccc7 --- /dev/null +++ b/src/database/seeders/20240520152029-demo-user.js @@ -0,0 +1,48 @@ +'use strict'; + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.bulkInsert('Users', [{ + + userId: 1, + name: 'test1', + email: 'test1@email.com', + password: '1234', + status: 'active', + wishlistId: 1, + cartId: 1, + role: 'buyer', + createdAt: new Date(), + updatedAt: new Date() + }, { + userId: 2, + name: 'test2', + email: 'test2@email.com', + password: '1234', + status: 'active', + wishlistId: 2, + cartId: 2, + role: 'buyer', + createdAt: new Date(), + updatedAt: new Date() + }, + { + userId: 3, + name: 'test3', + email:'test3@email.com', + password: '1234', + status:'active', + wishlistId: 3, + cartId: 3, + role: 'buyer', + createdAt: new Date(), + updatedAt: new Date() + }], {}); + }, + + down: async (queryInterface, Sequelize) => { + // @ts-ignore + await queryInterface.bulkDelete('Users', null, {}); + } +}; diff --git a/src/database/seeders/20240520152858-demo-cart.js b/src/database/seeders/20240520152858-demo-cart.js new file mode 100644 index 0000000..a2a809c --- /dev/null +++ b/src/database/seeders/20240520152858-demo-cart.js @@ -0,0 +1,30 @@ +'use strict'; + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.bulkInsert('Carts', [{ + + cartId: 1, + userId: 1, + createdAt: new Date(), + updatedAt: new Date() + }, { + cartId: 2, + userId: 2, + createdAt: new Date(), + updatedAt: new Date() + }, + { + cartId: 3, + userId: 3, + createdAt: new Date(), + updatedAt: new Date() + }], {}); + }, + + down: async (queryInterface, Sequelize) => { + // @ts-ignore + await queryInterface.bulkDelete('Carts', null, {}); + } +} diff --git a/src/database/seeders/20240520153205-demo-vendor.js b/src/database/seeders/20240520153205-demo-vendor.js new file mode 100644 index 0000000..890f96c --- /dev/null +++ b/src/database/seeders/20240520153205-demo-vendor.js @@ -0,0 +1,29 @@ +'use strict'; + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.bulkInsert('Vendors', [{ + vendorId: 1, + userId: 3, + storeName: 'vendorStore1', + address: { district: 'gasabo' }, + TIN: 12312, + bankAccount: 12312, + paymentDetails: { + phoneNumber: '07870000001' + }, + createdAt: new Date(), + updatedAt: new Date() + }], {}); + }, + + down: async (queryInterface, Sequelize) => { + // @ts-ignore + await queryInterface.bulkDelete('Vendors', null, {}); + } +}; + + + + diff --git a/src/database/seeders/20240520153801-demo-product.js b/src/database/seeders/20240520153801-demo-product.js new file mode 100644 index 0000000..0757739 --- /dev/null +++ b/src/database/seeders/20240520153801-demo-product.js @@ -0,0 +1,47 @@ +'use strict'; + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.bulkInsert('Products', [{ + productId: 1, + vendorId: 1, + name: 'Shoe', + description: 'This is a shoe', + discount: '2', + price: 1000, + quantity: 150, + createdAt: new Date(), + updatedAt: new Date() + }, { + productId: 2, + vendorId: 1, + name: 'Shirt', + description: 'This is a shirt', + discount: '5', + price: 1500, + quantity: 100, + createdAt: new Date(), + updatedAt: new Date() + }, + { + productId: 3, + vendorId: 1, + name: 'Shirt', + description: 'This is a shirt', + discount: '5', + price: 2500, + quantity: 100, + createdAt: new Date(), + updatedAt: new Date() + }], {}); + }, + + down: async (queryInterface, Sequelize) => { + // @ts-ignore + await queryInterface.bulkDelete('Products', null, {}); + } +}; + + + From fb642212721830a14666c2685533bc3b35d067f8 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 21 May 2024 22:13:59 +0200 Subject: [PATCH 08/24] seeder for the users model --- .../seeders/20240520152029-demo-user.js | 48 ---------- .../seeders/20240520152858-demo-cart.js | 30 ------ .../seeders/20240520153205-demo-vendor.js | 29 ------ .../seeders/20240520153801-demo-product.js | 47 ---------- .../seeders/20240521193841-seed-users.js | 91 +++++++++++++++++++ src/database/seeders/users.ts | 8 -- 6 files changed, 91 insertions(+), 162 deletions(-) delete mode 100644 src/database/seeders/20240520152029-demo-user.js delete mode 100644 src/database/seeders/20240520152858-demo-cart.js delete mode 100644 src/database/seeders/20240520153205-demo-vendor.js delete mode 100644 src/database/seeders/20240520153801-demo-product.js create mode 100644 src/database/seeders/20240521193841-seed-users.js delete mode 100644 src/database/seeders/users.ts diff --git a/src/database/seeders/20240520152029-demo-user.js b/src/database/seeders/20240520152029-demo-user.js deleted file mode 100644 index 277ccc7..0000000 --- a/src/database/seeders/20240520152029-demo-user.js +++ /dev/null @@ -1,48 +0,0 @@ -'use strict'; - -/** @type {import('sequelize-cli').Migration} */ -module.exports = { - up: async (queryInterface, Sequelize) => { - await queryInterface.bulkInsert('Users', [{ - - userId: 1, - name: 'test1', - email: 'test1@email.com', - password: '1234', - status: 'active', - wishlistId: 1, - cartId: 1, - role: 'buyer', - createdAt: new Date(), - updatedAt: new Date() - }, { - userId: 2, - name: 'test2', - email: 'test2@email.com', - password: '1234', - status: 'active', - wishlistId: 2, - cartId: 2, - role: 'buyer', - createdAt: new Date(), - updatedAt: new Date() - }, - { - userId: 3, - name: 'test3', - email:'test3@email.com', - password: '1234', - status:'active', - wishlistId: 3, - cartId: 3, - role: 'buyer', - createdAt: new Date(), - updatedAt: new Date() - }], {}); - }, - - down: async (queryInterface, Sequelize) => { - // @ts-ignore - await queryInterface.bulkDelete('Users', null, {}); - } -}; diff --git a/src/database/seeders/20240520152858-demo-cart.js b/src/database/seeders/20240520152858-demo-cart.js deleted file mode 100644 index a2a809c..0000000 --- a/src/database/seeders/20240520152858-demo-cart.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict'; - -/** @type {import('sequelize-cli').Migration} */ -module.exports = { - up: async (queryInterface, Sequelize) => { - await queryInterface.bulkInsert('Carts', [{ - - cartId: 1, - userId: 1, - createdAt: new Date(), - updatedAt: new Date() - }, { - cartId: 2, - userId: 2, - createdAt: new Date(), - updatedAt: new Date() - }, - { - cartId: 3, - userId: 3, - createdAt: new Date(), - updatedAt: new Date() - }], {}); - }, - - down: async (queryInterface, Sequelize) => { - // @ts-ignore - await queryInterface.bulkDelete('Carts', null, {}); - } -} diff --git a/src/database/seeders/20240520153205-demo-vendor.js b/src/database/seeders/20240520153205-demo-vendor.js deleted file mode 100644 index 890f96c..0000000 --- a/src/database/seeders/20240520153205-demo-vendor.js +++ /dev/null @@ -1,29 +0,0 @@ -'use strict'; - -/** @type {import('sequelize-cli').Migration} */ -module.exports = { - up: async (queryInterface, Sequelize) => { - await queryInterface.bulkInsert('Vendors', [{ - vendorId: 1, - userId: 3, - storeName: 'vendorStore1', - address: { district: 'gasabo' }, - TIN: 12312, - bankAccount: 12312, - paymentDetails: { - phoneNumber: '07870000001' - }, - createdAt: new Date(), - updatedAt: new Date() - }], {}); - }, - - down: async (queryInterface, Sequelize) => { - // @ts-ignore - await queryInterface.bulkDelete('Vendors', null, {}); - } -}; - - - - diff --git a/src/database/seeders/20240520153801-demo-product.js b/src/database/seeders/20240520153801-demo-product.js deleted file mode 100644 index 0757739..0000000 --- a/src/database/seeders/20240520153801-demo-product.js +++ /dev/null @@ -1,47 +0,0 @@ -'use strict'; - -/** @type {import('sequelize-cli').Migration} */ -module.exports = { - up: async (queryInterface, Sequelize) => { - await queryInterface.bulkInsert('Products', [{ - productId: 1, - vendorId: 1, - name: 'Shoe', - description: 'This is a shoe', - discount: '2', - price: 1000, - quantity: 150, - createdAt: new Date(), - updatedAt: new Date() - }, { - productId: 2, - vendorId: 1, - name: 'Shirt', - description: 'This is a shirt', - discount: '5', - price: 1500, - quantity: 100, - createdAt: new Date(), - updatedAt: new Date() - }, - { - productId: 3, - vendorId: 1, - name: 'Shirt', - description: 'This is a shirt', - discount: '5', - price: 2500, - quantity: 100, - createdAt: new Date(), - updatedAt: new Date() - }], {}); - }, - - down: async (queryInterface, Sequelize) => { - // @ts-ignore - await queryInterface.bulkDelete('Products', null, {}); - } -}; - - - diff --git a/src/database/seeders/20240521193841-seed-users.js b/src/database/seeders/20240521193841-seed-users.js new file mode 100644 index 0000000..6f5d88f --- /dev/null +++ b/src/database/seeders/20240521193841-seed-users.js @@ -0,0 +1,91 @@ +'use strict'; + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface, Sequelize) { + const profileUrl = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSXhCG6nff2emBYOKGHb6jU2zQ4C2m0LBg4Mj-eydwZyg&s' + await queryInterface.bulkInsert('Users', [ + { + userId: Sequelize.UUIDV4(), + name: 'User1', + email: 'user1@email.com', + password: 'password1', + status: 'active', + wishlistId: null, + cartId: null, + role: 'buyer', + profile: profileUrl, + createdAt: new Date(), + updatedAt: new Date() + }, + { + userId: Sequelize.UUIDV4(), + name: 'User2', + email: 'user2@email.com', + password: 'password1', + status: 'active', + wishlistId: null, + cartId: null, + role: 'buyer', + profile: profileUrl, + createdAt: new Date(), + updatedAt: new Date() + }, { + userId: Sequelize.UUIDV4(), + name: 'User3', + email: 'user3@email.com', + password: 'password1', + status: 'active', + wishlistId: null, + cartId: null, + role: 'buyer', + profile: 'profile3', + createdAt: new Date(), + updatedAt: new Date() + }, + { + userId: Sequelize.UUIDV4(), + name: 'User4', + email: 'user4@email.com', + password: 'password1', + status: 'active', + wishlistId: null, + cartId: null, + role: 'vendor', + profile: profileUrl, + createdAt: new Date(), + updatedAt: new Date() + }, + { + userId: Sequelize.UUIDV4(), + name: 'User5', + email: 'user5@email.com', + password: 'password1', + status: 'active', + wishlistId: null, + cartId: null, + role: 'vendor', + profile: profileUrl, + createdAt: new Date(), + updatedAt: new Date() + }, { + userId: Sequelize.UUIDV4(), + name: 'User6', + email: 'user6@email.com', + password: 'password1', + status: 'active', + wishlistId: null, + cartId: null, + role: 'vendor', + profile: profileUrl, + createdAt: new Date(), + updatedAt: new Date() + } + ], {}); + }, + + async down (queryInterface, Sequelize) { + // @ts-ignore + await queryInterface.bulkDelete('Users', null, {}); + } +}; diff --git a/src/database/seeders/users.ts b/src/database/seeders/users.ts deleted file mode 100644 index 4716b2e..0000000 --- a/src/database/seeders/users.ts +++ /dev/null @@ -1,8 +0,0 @@ -export const userss = [ - { - username: "Imanishimwe" - }, - { - username: "Rukundo" - }, -] \ No newline at end of file From 9f8fccaa7ceca673f0c02722fea5dd07a4c44690 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 21 May 2024 22:34:38 +0200 Subject: [PATCH 09/24] seeder for the carts model --- .../seeders/20240521193841-seed-users.js | 6 ++-- .../seeders/20240521201427-seed-carts.js | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 src/database/seeders/20240521201427-seed-carts.js diff --git a/src/database/seeders/20240521193841-seed-users.js b/src/database/seeders/20240521193841-seed-users.js index 6f5d88f..adf4859 100644 --- a/src/database/seeders/20240521193841-seed-users.js +++ b/src/database/seeders/20240521193841-seed-users.js @@ -43,7 +43,7 @@ module.exports = { createdAt: new Date(), updatedAt: new Date() }, - { + { userId: Sequelize.UUIDV4(), name: 'User4', email: 'user4@email.com', @@ -56,7 +56,7 @@ module.exports = { createdAt: new Date(), updatedAt: new Date() }, - { + { userId: Sequelize.UUIDV4(), name: 'User5', email: 'user5@email.com', @@ -84,7 +84,7 @@ module.exports = { ], {}); }, - async down (queryInterface, Sequelize) { + async down(queryInterface, Sequelize) { // @ts-ignore await queryInterface.bulkDelete('Users', null, {}); } diff --git a/src/database/seeders/20240521201427-seed-carts.js b/src/database/seeders/20240521201427-seed-carts.js new file mode 100644 index 0000000..b7105f7 --- /dev/null +++ b/src/database/seeders/20240521201427-seed-carts.js @@ -0,0 +1,30 @@ +'use strict'; + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface, Sequelize) { + const [users] = await queryInterface.sequelize.query(`SELECT userId FROM Users;`); + + const carts = users.map(user => ({ + cartId: Sequelize.UUIDV4(), + userId: user, + createdAt: new Date(), + updatedAt: new Date() + })); + + await queryInterface.bulkInsert('Carts', carts, {}); + + for (const cart of carts) { + await queryInterface.bulkUpdate('Users', + { cartId: cart.cartId }, + { userId: cart.userId } + ); + } + }, + + async down(queryInterface, Sequelize) { + // @ts-ignore + await queryInterface.bulkDelete('Carts', null, {}); + await queryInterface.bulkUpdate('Users', { cartId: null }, { cartId: { [Sequelize.Op.ne]: null } }); + } +}; From 0ad16887e509767f57f281ed6ac61512e1ea70c2 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 22 May 2024 08:36:25 +0200 Subject: [PATCH 10/24] made some changes in the datatypes --- src/database/migrations/20240520101722-create-user.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/database/migrations/20240520101722-create-user.js b/src/database/migrations/20240520101722-create-user.js index fd58e0c..a0b134e 100644 --- a/src/database/migrations/20240520101722-create-user.js +++ b/src/database/migrations/20240520101722-create-user.js @@ -15,7 +15,8 @@ module.exports = { }, email:{ type: Sequelize.STRING, - allowNull: false + allowNull: false, + unique: true }, password:{ type: Sequelize.STRING, @@ -52,4 +53,4 @@ module.exports = { async down(queryInterface, Sequelize) { await queryInterface.dropTable('Users'); } -}; \ No newline at end of file +}; From f33808c15f7769a0b01d21511205eaf93b52ffa2 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 22 May 2024 08:43:07 +0200 Subject: [PATCH 11/24] made some changes in the datatypes in vendor --- .../migrations/20240520134354-create-vendor.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/database/migrations/20240520134354-create-vendor.js b/src/database/migrations/20240520134354-create-vendor.js index cf3bb22..06bd66d 100644 --- a/src/database/migrations/20240520134354-create-vendor.js +++ b/src/database/migrations/20240520134354-create-vendor.js @@ -26,11 +26,13 @@ module.exports = { allowNull: false }, TIN:{ - type: Sequelize.INTEGER, - allowNull: false + type: Sequelize.BIGINT, + allowNull: false, + unique: true }, bankAccount:{ - type: Sequelize.INTEGER, + type: Sequelize.BIGINT, + unique: true }, paymentDetails: { type: Sequelize.JSONB @@ -52,4 +54,4 @@ module.exports = { async down(queryInterface, Sequelize) { await queryInterface.dropTable('Vendors'); } -}; \ No newline at end of file +}; From 899ad305ded73672d3385a4808fad5bbb45eb9c8 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 22 May 2024 08:45:15 +0200 Subject: [PATCH 12/24] seeder for the users and carts --- .../seeders/20240521193841-seed-users.js | 23 +++++++++++-------- .../seeders/20240521201427-seed-carts.js | 14 ++++++++--- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/database/seeders/20240521193841-seed-users.js b/src/database/seeders/20240521193841-seed-users.js index adf4859..3bfbb41 100644 --- a/src/database/seeders/20240521193841-seed-users.js +++ b/src/database/seeders/20240521193841-seed-users.js @@ -1,12 +1,14 @@ 'use strict'; +const { v4: uuidv4 } = require('uuid'); + /** @type {import('sequelize-cli').Migration} */ module.exports = { async up(queryInterface, Sequelize) { const profileUrl = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSXhCG6nff2emBYOKGHb6jU2zQ4C2m0LBg4Mj-eydwZyg&s' await queryInterface.bulkInsert('Users', [ { - userId: Sequelize.UUIDV4(), + userId: uuidv4(), name: 'User1', email: 'user1@email.com', password: 'password1', @@ -19,7 +21,7 @@ module.exports = { updatedAt: new Date() }, { - userId: Sequelize.UUIDV4(), + userId: uuidv4(), name: 'User2', email: 'user2@email.com', password: 'password1', @@ -31,7 +33,7 @@ module.exports = { createdAt: new Date(), updatedAt: new Date() }, { - userId: Sequelize.UUIDV4(), + userId: uuidv4(), name: 'User3', email: 'user3@email.com', password: 'password1', @@ -39,44 +41,45 @@ module.exports = { wishlistId: null, cartId: null, role: 'buyer', - profile: 'profile3', + profile: profileUrl, createdAt: new Date(), updatedAt: new Date() }, { - userId: Sequelize.UUIDV4(), + userId: uuidv4(), name: 'User4', email: 'user4@email.com', password: 'password1', status: 'active', wishlistId: null, cartId: null, - role: 'vendor', + role: 'buyer', profile: profileUrl, createdAt: new Date(), updatedAt: new Date() }, { - userId: Sequelize.UUIDV4(), + userId: uuidv4(), name: 'User5', email: 'user5@email.com', password: 'password1', status: 'active', wishlistId: null, cartId: null, - role: 'vendor', + role: 'buyer', profile: profileUrl, createdAt: new Date(), updatedAt: new Date() }, { - userId: Sequelize.UUIDV4(), + + userId: uuidv4(), name: 'User6', email: 'user6@email.com', password: 'password1', status: 'active', wishlistId: null, cartId: null, - role: 'vendor', + role: 'buyer', profile: profileUrl, createdAt: new Date(), updatedAt: new Date() diff --git a/src/database/seeders/20240521201427-seed-carts.js b/src/database/seeders/20240521201427-seed-carts.js index b7105f7..cb4bf31 100644 --- a/src/database/seeders/20240521201427-seed-carts.js +++ b/src/database/seeders/20240521201427-seed-carts.js @@ -1,13 +1,21 @@ 'use strict'; +const { v4: uuidv4 } = require('uuid'); + /** @type {import('sequelize-cli').Migration} */ module.exports = { async up(queryInterface, Sequelize) { - const [users] = await queryInterface.sequelize.query(`SELECT userId FROM Users;`); + console.log('Getting the users') + const [users] = await queryInterface.sequelize.query(`SELECT "userId" FROM "Users"`); + + users.map(user => ( + console.log('The users ', user) + )) const carts = users.map(user => ({ - cartId: Sequelize.UUIDV4(), - userId: user, + cartId: uuidv4(), + // @ts-ignore + userId: user.userId, createdAt: new Date(), updatedAt: new Date() })); From 220c129314f9f6dc98dcffdc36ae6d37bd67500a Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 22 May 2024 08:49:27 +0200 Subject: [PATCH 13/24] seeder for the vendors model --- .../seeders/20240521204207-seed-vendors.js | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/database/seeders/20240521204207-seed-vendors.js diff --git a/src/database/seeders/20240521204207-seed-vendors.js b/src/database/seeders/20240521204207-seed-vendors.js new file mode 100644 index 0000000..a8623d0 --- /dev/null +++ b/src/database/seeders/20240521204207-seed-vendors.js @@ -0,0 +1,50 @@ +'use strict'; + +const { v4: uuidv4 } = require('uuid'); + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface, Sequelize) { + const [users] = await queryInterface.sequelize.query(` + SELECT "userId" + FROM "Users" + ORDER BY "createdAt" DESC + LIMIT 3; + `); + + const vendors = users.map(user => ({ + vendorId: uuidv4(), + // @ts-ignore + userId: user.userId, + storeName: `Store ${Math.floor(Math.random() * (11))}`, + address: JSON.stringify({ + street: 'KG 111 ST', + city: 'Kigali' + }), + TIN: Math.floor(Math.random() * 100000000), + bankAccount: Math.floor(Math.random() * 1000000000), + paymentDetails: JSON.stringify({ + method: 'Bank Transfer', + bankName: 'Bank Of Kigali' + }), + status: 'pending', + createdAt: new Date(), + updatedAt: new Date() + })) + + await queryInterface.bulkInsert('Vendors', vendors, {}); + + await queryInterface.bulkUpdate('Users', + { role: 'vendor' }, + // @ts-ignore + { userId: users.map(user => user.userId) } + ); + }, + + + async down(queryInterface, Sequelize) { + // @ts-ignore + await queryInterface.bulkDelete('Vendors', null, {}); + await queryInterface.bulkUpdate('Users', { role: 'buyer' }, { role: 'vendor' }); + } +}; From 144bb5be96b6589f565dfaa261391bfa105c6424 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 22 May 2024 09:08:22 +0200 Subject: [PATCH 14/24] changed the datatype for discount --- src/database/migrations/20240520140651-create-product.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/database/migrations/20240520140651-create-product.js b/src/database/migrations/20240520140651-create-product.js index 4ca9545..1ea4ec6 100644 --- a/src/database/migrations/20240520140651-create-product.js +++ b/src/database/migrations/20240520140651-create-product.js @@ -29,7 +29,7 @@ module.exports = { allowNull: false }, discount:{ - type: Sequelize.STRING, + type: Sequelize.DOUBLE, allowNull: false }, price:{ @@ -55,4 +55,4 @@ module.exports = { async down(queryInterface, Sequelize) { await queryInterface.dropTable('Products'); } -}; \ No newline at end of file +}; From a0c844222a50cfcb8b8585e74548aeb1c9587230 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 22 May 2024 09:08:52 +0200 Subject: [PATCH 15/24] seeder for the products model --- .../seeders/20240522064825-seed-products.js | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/database/seeders/20240522064825-seed-products.js diff --git a/src/database/seeders/20240522064825-seed-products.js b/src/database/seeders/20240522064825-seed-products.js new file mode 100644 index 0000000..cf5a0fa --- /dev/null +++ b/src/database/seeders/20240522064825-seed-products.js @@ -0,0 +1,40 @@ +'use strict'; + +const { v4: uuidv4 } = require('uuid'); + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface, Sequelize) { + const imageUrl = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSXhCG6nff2emBYOKGHb6jU2zQ4C2m0LBg4Mj-eydwZyg&s' + + const [vendors] = await queryInterface.sequelize.query(` + SELECT "vendorId" + FROM "Vendors" + ORDER BY "createdAt" DESC + LIMIT 3; + `); + + const products = vendors.map(vendor => ({ + productId: uuidv4(), + // @ts-ignore + vendorId: vendor.vendorId, + name: 'nike shoes', + image: imageUrl, + description: 'These are nike shoes.', + discount: 2, + price: 12000, + quantity: 100, + category: 'Shoes', + createdAt: new Date(), + updatedAt: new Date() + })) + + await queryInterface.bulkInsert('Products', products, {}); + }, + + + async down(queryInterface, Sequelize) { + // @ts-ignore + await queryInterface.bulkDelete('Products', null, {}); + } +}; From 5ee18caf0bb073972adfd4c5bfb80bb704ef68b8 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 22 May 2024 09:25:21 +0200 Subject: [PATCH 16/24] seeder for the wishlists model --- .../seeders/20240522070922-seed-wishlists.js | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/database/seeders/20240522070922-seed-wishlists.js diff --git a/src/database/seeders/20240522070922-seed-wishlists.js b/src/database/seeders/20240522070922-seed-wishlists.js new file mode 100644 index 0000000..ecad181 --- /dev/null +++ b/src/database/seeders/20240522070922-seed-wishlists.js @@ -0,0 +1,50 @@ +'use strict'; + +// @ts-ignore +const { v4: uuidv4 } = require('uuid'); + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + // @ts-ignore + async up(queryInterface, Sequelize) { + const [users] = await queryInterface.sequelize.query(` + SELECT "userId" + FROM "Users" + ORDER BY "createdAt" DESC + LIMIT 3; + `); + + const [products] = await queryInterface.sequelize.query(` + SELECT "productId" + FROM "Products" + LIMIT 3; + `); + + const wishlists = users.flatMap(user => + products.map(product => ({ + wishlistId: uuidv4(), + // @ts-ignore + userId: user.userId, + // @ts-ignore + productId: product.productId, + createdAt: new Date(), + updatedAt: new Date() + })) + ); + + await queryInterface.bulkInsert('Wishlists', wishlists, {}); + + for (const wishlist of wishlists) { + await queryInterface.bulkUpdate('Users', + { wishlistId: wishlist.wishlistId }, + { userId: wishlist.userId } + ); + } + }, + + async down(queryInterface, Sequelize) { + // @ts-ignore + await queryInterface.bulkDelete('Carts', null, {}); + await queryInterface.bulkUpdate('Users', { wishlistId: null }, { wishlistId: { [Sequelize.Op.ne]: null } }); + } +}; From b4be478611a176109a26cdfeca3cde3a293e12b3 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 22 May 2024 09:46:42 +0200 Subject: [PATCH 17/24] fixed a typo in the attributes quantity --- .../migrations/20240520141938-create-cart-item.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/database/migrations/20240520141938-create-cart-item.js b/src/database/migrations/20240520141938-create-cart-item.js index a81b65a..e07a285 100644 --- a/src/database/migrations/20240520141938-create-cart-item.js +++ b/src/database/migrations/20240520141938-create-cart-item.js @@ -11,24 +11,23 @@ module.exports = { }, cartId: { type: Sequelize.STRING, - references:{ + references: { model: 'Carts', key: 'cartId' } }, - productId:{ + productId: { type: Sequelize.STRING, - references:{ + references: { model: 'Products', key: 'productId' } }, - quantinty:{ + quantity: { type: Sequelize.INTEGER, allowNull: false, defaultValue: 1 - }, price: { type: Sequelize.INTEGER, @@ -47,4 +46,4 @@ module.exports = { async down(queryInterface, Sequelize) { await queryInterface.dropTable('CartItems'); } -}; \ No newline at end of file +}; From 406e7b65cd300a99dab39a42c00aa85944b65423 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 22 May 2024 09:47:42 +0200 Subject: [PATCH 18/24] seeder for the model cartitems --- .../seeders/20240522073044-seed-cartitems.js | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/database/seeders/20240522073044-seed-cartitems.js diff --git a/src/database/seeders/20240522073044-seed-cartitems.js b/src/database/seeders/20240522073044-seed-cartitems.js new file mode 100644 index 0000000..9ae691a --- /dev/null +++ b/src/database/seeders/20240522073044-seed-cartitems.js @@ -0,0 +1,44 @@ +'use strict'; + +const { v4: uuidv4 } = require('uuid'); + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface, Sequelize) { + const [carts] = await queryInterface.sequelize.query(` + SELECT "cartId" + FROM "Carts" + ORDER BY "createdAt" DESC + LIMIT 3; + `); + + const [products] = await queryInterface.sequelize.query(` + SELECT "productId", "price" + FROM "Products" + LIMIT 3; + `); + + const quantity = 10 + + const cartItems = carts.flatMap(cart => + products.map(product => ({ + cartitemsid: uuidv4(), + // @ts-ignore + cartId: cart.cartId, + // @ts-ignore + productId: product.productId, + quantity: quantity, + // @ts-ignore + price: product.price * quantity, + createdAt: new Date(), + updatedAt: new Date() + }))) + + await queryInterface.bulkInsert('CartItems', cartItems, {}); + }, + + async down(queryInterface, Sequelize) { + // @ts-ignore + await queryInterface.bulkDelete('CartItems', null, {}) + } +}; From 9e6c627672b87f89b7f65e7884dc97db98f320ab Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 22 May 2024 10:03:25 +0200 Subject: [PATCH 19/24] seeder for the model orders --- .../seeders/20240522075149-seed-orders.js | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/database/seeders/20240522075149-seed-orders.js diff --git a/src/database/seeders/20240522075149-seed-orders.js b/src/database/seeders/20240522075149-seed-orders.js new file mode 100644 index 0000000..e8acd39 --- /dev/null +++ b/src/database/seeders/20240522075149-seed-orders.js @@ -0,0 +1,49 @@ +'use strict'; + +const { v4: uuidv4 } = require('uuid'); + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface, Sequelize) { + const [users] = await queryInterface.sequelize.query(` + SELECT "userId" + FROM "Users" + LIMIT 3; + `); + + const [products] = await queryInterface.sequelize.query(` + SELECT "productId", "name" + FROM "Products" + LIMIT 3; + `); + + const orders = users.flatMap(user => + products.map(product => ({ + orderId: uuidv4(), + deliveryAddress: JSON.stringify({ + street: 'KG 111 ST', + city: 'Kigali' + }), + // @ts-ignore + userId: user.userId, + paymentMethod: 'Bank Transfer', + status: 'pending', + products: JSON.stringify({ + // @ts-ignore + productId: product.productId, + // @ts-ignore + productName: product.name + }), + createdAt: new Date(), + updatedAt: new Date() + }))) + + await queryInterface.bulkInsert('Orders', orders, {}); + + }, + + async down(queryInterface, Sequelize) { + // @ts-ignore + await queryInterface.bulkDelete('Orders', null, {}) + } +}; From 4c130c685022ee796e15d3e0f67bded9b3adec60 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 22 May 2024 10:09:10 +0200 Subject: [PATCH 20/24] created seeder for the admins model and made the email unique for each admin --- .../migrations/20240520143222-create-admin.js | 5 +-- .../seeders/20240522080345-seed-admins.js | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 src/database/seeders/20240522080345-seed-admins.js diff --git a/src/database/migrations/20240520143222-create-admin.js b/src/database/migrations/20240520143222-create-admin.js index 699f054..2214d73 100644 --- a/src/database/migrations/20240520143222-create-admin.js +++ b/src/database/migrations/20240520143222-create-admin.js @@ -10,7 +10,8 @@ module.exports = { defaultValue: Sequelize.UUIDV4 }, email: { - type: Sequelize.STRING + type: Sequelize.STRING, + unique: true }, password: { type: Sequelize.STRING @@ -28,4 +29,4 @@ module.exports = { async down(queryInterface, Sequelize) { await queryInterface.dropTable('Admins'); } -}; \ No newline at end of file +}; diff --git a/src/database/seeders/20240522080345-seed-admins.js b/src/database/seeders/20240522080345-seed-admins.js new file mode 100644 index 0000000..605b8e0 --- /dev/null +++ b/src/database/seeders/20240522080345-seed-admins.js @@ -0,0 +1,31 @@ +'use strict'; + +const { v4: uuidv4 } = require('uuid'); + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface, Sequelize) { + await queryInterface.bulkInsert('Admins', [ + { + adminId: uuidv4(), + email: 'admin1@email.com', + password: 'password1', + createdAt: new Date(), + updatedAt: new Date() + }, + { + adminId: uuidv4(), + email: 'admin2@email.com', + password: 'password1', + createdAt: new Date(), + updatedAt: new Date() + } + ], {}); + }, + + async down(queryInterface, Sequelize) { + // @ts-ignore + await queryInterface.bulkDelete('Admins', null, {}); + + } +}; From 788bf9255607e6d391b07b39c4f81f8ec5020b3a Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 22 May 2024 10:14:59 +0200 Subject: [PATCH 21/24] seeder for the messages model --- .../seeders/20240522081008-seed-messages.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/database/seeders/20240522081008-seed-messages.js diff --git a/src/database/seeders/20240522081008-seed-messages.js b/src/database/seeders/20240522081008-seed-messages.js new file mode 100644 index 0000000..a937d70 --- /dev/null +++ b/src/database/seeders/20240522081008-seed-messages.js @@ -0,0 +1,32 @@ +'use strict'; + +const { v4: uuidv4 } = require('uuid'); + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface, Sequelize) { + await queryInterface.bulkInsert('Messages', [ + { + contactId: uuidv4(), + name: 'Testing', + email: 'test@email.com', + content: 'Hello thank you', + createdAt: new Date(), + updatedAt: new Date() + }, + { + contactId: uuidv4(), + name: 'Testing', + email: 'test@email.com', + content: 'Hello thanks', + createdAt: new Date(), + updatedAt: new Date() + } + ], {}); + }, + + async down(queryInterface, Sequelize) { + // @ts-ignore + await queryInterface.bulkDelete('Messages', null, {}); + } +}; From 4bf7d5a955d7a8aab0abff7ebdaa497c59f09e0f Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 22 May 2024 10:22:28 +0200 Subject: [PATCH 22/24] created seeder for the subscriptions model and made the email unique for each subscriber --- .../20240520143257-create-subscription.js | 5 +-- .../20240522081616-seed-subscriptions.js | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/database/seeders/20240522081616-seed-subscriptions.js diff --git a/src/database/migrations/20240520143257-create-subscription.js b/src/database/migrations/20240520143257-create-subscription.js index 4f64265..e3c1b8f 100644 --- a/src/database/migrations/20240520143257-create-subscription.js +++ b/src/database/migrations/20240520143257-create-subscription.js @@ -10,7 +10,8 @@ module.exports = { defaultValue: Sequelize.UUIDV4 }, email: { - type: Sequelize.STRING + type: Sequelize.STRING, + unique: true }, createdAt: { allowNull: false, @@ -25,4 +26,4 @@ module.exports = { async down(queryInterface, Sequelize) { await queryInterface.dropTable('Subscriptions'); } -}; \ No newline at end of file +}; diff --git a/src/database/seeders/20240522081616-seed-subscriptions.js b/src/database/seeders/20240522081616-seed-subscriptions.js new file mode 100644 index 0000000..bedf08c --- /dev/null +++ b/src/database/seeders/20240522081616-seed-subscriptions.js @@ -0,0 +1,33 @@ +'use strict'; + +const { v4: uuidv4 } = require('uuid'); + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface, Sequelize) { + await queryInterface.bulkInsert('Subscriptions', [ + { + subscriptionId: uuidv4(), + email: 'subscriber1@gmail.com', + createdAt: new Date(), + updatedAt: new Date() + }, + { + subscriptionId: uuidv4(), + email: 'subscriber2@gmail.com', + createdAt: new Date(), + updatedAt: new Date() + }, + { + subscriptionId: uuidv4(), + email: 'subscriber3@gmail.com', + createdAt: new Date(), + updatedAt: new Date() + }], {}) + }, + + async down(queryInterface, Sequelize) { + // @ts-ignore + await queryInterface.bulkDelete('Subscriptions', null, {}); + } +}; From f6e1ccbe27ea514def598ae9541815cce6dce993 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 22 May 2024 10:36:03 +0200 Subject: [PATCH 23/24] seeder for the ratings model --- .../seeders/20240522082250-seed-ratings.js | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/database/seeders/20240522082250-seed-ratings.js diff --git a/src/database/seeders/20240522082250-seed-ratings.js b/src/database/seeders/20240522082250-seed-ratings.js new file mode 100644 index 0000000..a9bd727 --- /dev/null +++ b/src/database/seeders/20240522082250-seed-ratings.js @@ -0,0 +1,40 @@ +'use strict'; + +const { v4: uuidv4 } = require('uuid'); + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + async up(queryInterface, Sequelize) { + const [users] = await queryInterface.sequelize.query(` + SELECT "userId" + FROM "Users" + LIMIT 3; + `); + + const [vendors] = await queryInterface.sequelize.query(` + SELECT "vendorId" + FROM "Vendors" + LIMIT 3; + `); + + const ratings = users.flatMap(user => + vendors.map(vendor => ({ + ratingId: uuidv4(), + ratingScore: 5, + // @ts-ignore + userId: user.userId, + // @ts-ignore + vendorId: vendor.vendorId, + createdAt: new Date(), + updatedAt: new Date() + }))) + + await queryInterface.bulkInsert('Ratings', ratings, {}); + + }, + + async down(queryInterface, Sequelize) { + // @ts-ignore + await queryInterface.bulkDelete('Ratings', null, {}) + } +}; From d312e462c9d0a979eb623983be3d12ac7579ac31 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 22 May 2024 10:39:53 +0200 Subject: [PATCH 24/24] seeders are done --- package-lock.json | 21 +++++++++++++++++---- package.json | 3 ++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index eb61f2b..4fcec39 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,7 +31,8 @@ "supertest": "^7.0.0", "swagger-jsdoc": "^6.2.8", "swagger-ui-express": "^5.0.0", - "ts-node": "^10.9.2" + "ts-node": "^10.9.2", + "uuid": "^9.0.1" }, "devDependencies": { "@types/bcrypt": "^5.0.2", @@ -8724,6 +8725,14 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, + "node_modules/sequelize/node_modules/uuid": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", + "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/serve-static": { "version": "1.15.0", "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz", @@ -9581,9 +9590,13 @@ } }, "node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], "bin": { "uuid": "dist/bin/uuid" } diff --git a/package.json b/package.json index 99fb976..41713e0 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,8 @@ "supertest": "^7.0.0", "swagger-jsdoc": "^6.2.8", "swagger-ui-express": "^5.0.0", - "ts-node": "^10.9.2" + "ts-node": "^10.9.2", + "uuid": "^9.0.1" }, "devDependencies": { "@types/bcrypt": "^5.0.2",