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

adding two missing attributes #10

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
60d2b54
add dotenv
sevelinCa May 17, 2024
091be42
fix js files
sevelinCa May 17, 2024
07de754
add before and after
sevelinCa May 17, 2024
c2eb4c2
Create node.js.yml
berniceu May 13, 2024
851619c
Readme file created
Lapidis2 May 12, 2024
313f617
readme modified
Lapidis2 May 14, 2024
09d6015
started working on seeders
May 21, 2024
4f25b10
adding two missing attributes
sevelinCa May 21, 2024
780436a
Merge remote-tracking branch 'origin/ft-friday-demo' into ft-seeders
May 21, 2024
8383156
Merge branch 'ft-friday-demo' of https://github.com/atlp-rwanda/e-com…
May 21, 2024
fb64221
seeder for the users model
May 21, 2024
9f8fcca
seeder for the carts model
May 21, 2024
d40ea1b
add password attribute in user model
sevelinCa May 21, 2024
0ad1688
made some changes in the datatypes
May 22, 2024
f33808c
made some changes in the datatypes in vendor
May 22, 2024
899ad30
seeder for the users and carts
May 22, 2024
220c129
seeder for the vendors model
May 22, 2024
144bb5b
changed the datatype for discount
May 22, 2024
a0c8442
seeder for the products model
May 22, 2024
5ee18ca
seeder for the wishlists model
May 22, 2024
b4be478
fixed a typo in the attributes quantity
May 22, 2024
406e7b6
seeder for the model cartitems
May 22, 2024
9e6c627
seeder for the model orders
May 22, 2024
4c130c6
created seeder for the admins model and made the email unique for eac…
May 22, 2024
788bf92
seeder for the messages model
May 22, 2024
4bf7d5a
created seeder for the subscriptions model and made the email unique …
May 22, 2024
f6e1ccb
seeder for the ratings model
May 22, 2024
d312e46
seeders are done
May 22, 2024
dc10604
Merge pull request #12 from atlp-rwanda/ft-seeders
sevelinCa May 22, 2024
3b328c0
Merge branch 'ft-friday-demo' of https://github.com/atlp-rwanda/e-com…
May 22, 2024
29069f0
removed console logs used for debugging
May 22, 2024
0d4ea9e
Add is verfied attributes
sevelinCa May 22, 2024
c2a396d
changes in seeders of cart
sevelinCa May 22, 2024
2e0c36c
Correct mistake to product
sevelinCa May 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 4 additions & 0 deletions src/database/config/db.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const MODE:any = process.env.MODE || 'development'
const connectSequelize:Sequelize = new Sequelize(config[`${MODE}`].url,{
dialect: config[`${MODE}`].dialect,
dialectOptions: {
ssl: {
require: true,
rejectUnauthorized: true
}
}

})
Expand Down
14 changes: 10 additions & 4 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 All @@ -26,10 +27,10 @@ module.exports = {
defaultValue: 'active'
},
wishlistId:{
type: Sequelize.INTEGER,
type: Sequelize.STRING,
},
cartId: {
type: Sequelize.INTEGER
type: Sequelize.STRING
},
role: {
type: Sequelize.STRING,
Expand All @@ -39,6 +40,11 @@ module.exports = {
profile:{
type: Sequelize.STRING
},
isVerfied:{
type: Sequelize.BOOLEAN,
defaultValue: false

},
createdAt: {
allowNull: false,
type: Sequelize.DATE
Expand All @@ -52,4 +58,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');
}
};
};
2 changes: 1 addition & 1 deletion src/database/migrations/20240520143337-create-rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {
type: Sequelize.INTEGER
},
userId: {
type: Sequelize.INTEGER,
type: Sequelize.STRING,
references:{
model: 'Users',
key: 'userId'
Expand Down
14 changes: 8 additions & 6 deletions src/database/models/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import connectSequelize from "../config/db.config";
import { ftruncate } from "fs";

class Product extends Model {
public productId?: number
public productId?: string
public vendorId: any
public name!: string
public description!: string
public image!: string
public discount!: number
public price!: string
public quantity!: number
public vendorId: any
public category!: string

static associate(models: any) {
Product.hasMany(models.Wishlist,{
foreignKey: 'productId',
Expand All @@ -22,20 +24,20 @@ import { ftruncate } from "fs";
as: 'wishlists'

})
Product.belongsTo(models.Vendor,{
foreignKey: 'vendorId',
as: 'vendor'
})

}
}
Product.init({
productId: {type:DataTypes.UUID,primaryKey: true,defaultValue: DataTypes.UUIDV4},
vendorId: {type:DataTypes.STRING,primaryKey: true,defaultValue: DataTypes.UUIDV4},
name: {type:DataTypes.STRING,allowNull: false},
description: {type:DataTypes.STRING,allowNull: false},
image: {type:DataTypes.STRING,allowNull: false},
discount: {type:DataTypes.INTEGER,allowNull: false},
price: {type:DataTypes.INTEGER,allowNull: false},
quantity: {type:DataTypes.INTEGER,allowNull: true},
category: {type:DataTypes.STRING,allowNull: true},


}, {
sequelize: connectSequelize,
Expand Down
5 changes: 4 additions & 1 deletion src/database/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import connectSequelize from "../config/db.config";
public cartId?: string
public role!: string
public profile?: string
public isVerfied?: boolean

static associate(models: any) {
User.hasMany(models.Rating,{
Expand All @@ -32,11 +33,13 @@ 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},
role: {type:DataTypes.STRING,defaultValue:'buyer'},
profile: {type:DataTypes.STRING,defaultValue: "https://thumbs.dreamstime.com/b/default-avatar-profile-vector-user-profile-default-avatar-profile-vector-user-profile-profile-179376714.jpg"},
profile: {type:DataTypes.STRING,defaultValue: "https://thumbs.dreamstime.com/b/default-avatar-profile-vector-user-profile-default-avatar-profile-vector-user-profile-profile-179376714.jpg"},
isVerfied: {type:DataTypes.BOOLEAN,defaultValue: false}
}, {
sequelize: connectSequelize,
modelName: 'User',
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, {});
}
};
Loading