Skip to content

Commit

Permalink
Merge branch 'ft-friday-demo' of https://github.com/atlp-rwanda/e-com…
Browse files Browse the repository at this point in the history
…merce-crafters-bn into ft-friday-demo
  • Loading branch information
chris committed May 22, 2024
2 parents 8383156 + dc10604 commit 3b328c0
Show file tree
Hide file tree
Showing 21 changed files with 543 additions and 31 deletions.
21 changes: 17 additions & 4 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions src/database/migrations/20240520101722-create-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module.exports = {
},
email:{
type: Sequelize.STRING,
allowNull: false
allowNull: false,
unique: true
},
password:{
type: Sequelize.STRING,
Expand Down Expand Up @@ -52,4 +53,4 @@ module.exports = {
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('Users');
}
};
};
10 changes: 6 additions & 4 deletions src/database/migrations/20240520134354-create-vendor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,4 +54,4 @@ module.exports = {
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('Vendors');
}
};
};
4 changes: 2 additions & 2 deletions src/database/migrations/20240520140651-create-product.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module.exports = {
allowNull: false
},
discount:{
type: Sequelize.STRING,
type: Sequelize.DOUBLE,
allowNull: false
},
price:{
Expand All @@ -55,4 +55,4 @@ module.exports = {
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('Products');
}
};
};
11 changes: 5 additions & 6 deletions src/database/migrations/20240520141938-create-cart-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -47,4 +46,4 @@ module.exports = {
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('CartItems');
}
};
};
5 changes: 3 additions & 2 deletions src/database/migrations/20240520143222-create-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = {
defaultValue: Sequelize.UUIDV4
},
email: {
type: Sequelize.STRING
type: Sequelize.STRING,
unique: true
},
password: {
type: Sequelize.STRING
Expand All @@ -28,4 +29,4 @@ module.exports = {
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('Admins');
}
};
};
5 changes: 3 additions & 2 deletions src/database/migrations/20240520143257-create-subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ module.exports = {
defaultValue: Sequelize.UUIDV4
},
email: {
type: Sequelize.STRING
type: Sequelize.STRING,
unique: true
},
createdAt: {
allowNull: false,
Expand All @@ -25,4 +26,4 @@ module.exports = {
async down(queryInterface, Sequelize) {
await queryInterface.dropTable('Subscriptions');
}
};
};
1 change: 1 addition & 0 deletions src/database/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import connectSequelize from "../config/db.config";
userId: {type:DataTypes.UUID,primaryKey: true,defaultValue: DataTypes.UUIDV4},
name: {type:DataTypes.STRING,allowNull: false},
email: {type:DataTypes.STRING,allowNull: false},
password: {type:DataTypes.STRING,allowNull: false},
status: {type:DataTypes.STRING,defaultValue: 'active'},
wishlistId: {type:DataTypes.STRING},
cartId: {type:DataTypes.STRING},
Expand Down
94 changes: 94 additions & 0 deletions src/database/seeders/20240521193841-seed-users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
'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: uuidv4(),
name: 'User1',
email: '[email protected]',
password: 'password1',
status: 'active',
wishlistId: null,
cartId: null,
role: 'buyer',
profile: profileUrl,
createdAt: new Date(),
updatedAt: new Date()
},
{
userId: uuidv4(),
name: 'User2',
email: '[email protected]',
password: 'password1',
status: 'active',
wishlistId: null,
cartId: null,
role: 'buyer',
profile: profileUrl,
createdAt: new Date(),
updatedAt: new Date()
}, {
userId: uuidv4(),
name: 'User3',
email: '[email protected]',
password: 'password1',
status: 'active',
wishlistId: null,
cartId: null,
role: 'buyer',
profile: profileUrl,
createdAt: new Date(),
updatedAt: new Date()
},
{
userId: uuidv4(),
name: 'User4',
email: '[email protected]',
password: 'password1',
status: 'active',
wishlistId: null,
cartId: null,
role: 'buyer',
profile: profileUrl,
createdAt: new Date(),
updatedAt: new Date()
},
{
userId: uuidv4(),
name: 'User5',
email: '[email protected]',
password: 'password1',
status: 'active',
wishlistId: null,
cartId: null,
role: 'buyer',
profile: profileUrl,
createdAt: new Date(),
updatedAt: new Date()
}, {

userId: uuidv4(),
name: 'User6',
email: '[email protected]',
password: 'password1',
status: 'active',
wishlistId: null,
cartId: null,
role: 'buyer',
profile: profileUrl,
createdAt: new Date(),
updatedAt: new Date()
}
], {});
},

async down(queryInterface, Sequelize) {
// @ts-ignore
await queryInterface.bulkDelete('Users', null, {});
}
};
38 changes: 38 additions & 0 deletions src/database/seeders/20240521201427-seed-carts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';

const { v4: uuidv4 } = require('uuid');

/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
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: uuidv4(),
// @ts-ignore
userId: user.userId,
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 } });
}
};
50 changes: 50 additions & 0 deletions src/database/seeders/20240521204207-seed-vendors.js
Original file line number Diff line number Diff line change
@@ -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' });
}
};
Loading

0 comments on commit 3b328c0

Please sign in to comment.