update,
This commit is contained in:
53
tsc1877/task1/project/admin/db_seed/auth.js
Normal file
53
tsc1877/task1/project/admin/db_seed/auth.js
Normal file
@@ -0,0 +1,53 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
const bcrypt = require('bcrypt');
|
||||
const { sequelize } = require('./model');
|
||||
|
||||
function delay(time_ms) {
|
||||
return new Promise((res, rej) => {
|
||||
setTimeout(() => {
|
||||
res();
|
||||
}, time_ms);
|
||||
});
|
||||
}
|
||||
|
||||
const Auth = sequelize.define(
|
||||
'Auths',
|
||||
{
|
||||
uid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
username: { type: DataTypes.STRING, allowNull: false },
|
||||
password: { type: DataTypes.STRING, allowNull: false },
|
||||
session: { type: DataTypes.STRING, allowNull: false, defaultValue: '' },
|
||||
role: { type: DataTypes.STRING, allowNull: false, defaultValue: 'customer' },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
async function hashPassword(plainTextPassword) {
|
||||
const saltRounds = 10;
|
||||
return await bcrypt.hash(plainTextPassword, saltRounds);
|
||||
}
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
// create table
|
||||
await Auth.drop();
|
||||
await sequelize.sync();
|
||||
|
||||
let user_row, password;
|
||||
user_row = await Auth.create({
|
||||
username: 'admin@vtkhmall.com',
|
||||
password: await hashPassword('nimda'),
|
||||
role: 'admin',
|
||||
});
|
||||
user_row = await Auth.create({ username: 'cust1@vtkhmall.com', password: await hashPassword('1tsuc') });
|
||||
user_row = await Auth.create({ username: 'cust2@vtkhmall.com', password: await hashPassword('2tsuc') });
|
||||
user_row = await Auth.create({ username: 'cust3@vtkhmall.com', password: await hashPassword('3tsuc') });
|
||||
|
||||
// await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
54
tsc1877/task1/project/admin/db_seed/categories.js
Normal file
54
tsc1877/task1/project/admin/db_seed/categories.js
Normal file
@@ -0,0 +1,54 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('./model');
|
||||
|
||||
// const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
// host: 'mysql',
|
||||
// port: 3306,
|
||||
// dialect: 'mysql',
|
||||
// });
|
||||
|
||||
const Category = sequelize.define(
|
||||
'Categories',
|
||||
{
|
||||
cid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
name: { type: DataTypes.STRING, allowNull: false },
|
||||
description: { type: DataTypes.STRING, allowNull: false },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
// create table
|
||||
await Category.drop();
|
||||
await sequelize.sync();
|
||||
|
||||
let category;
|
||||
|
||||
category = await Category.create({ name: 'Bakery', description: 'Bread, pastries, cakes, cookies' });
|
||||
category = await Category.create({ name: 'Dairy', description: 'Milk, cheese, eggs, yogurt, butter' });
|
||||
category = await Category.create({
|
||||
name: 'Meat & Seafood',
|
||||
description: 'Raw meat products, poultry, fish, shellfish',
|
||||
});
|
||||
category = await Category.create({
|
||||
name: 'Deli Counter',
|
||||
description: 'Prepared foods such as sandwiches, salads, and cold cuts',
|
||||
});
|
||||
category = await Category.create({
|
||||
name: 'Frozen Foods',
|
||||
description: 'Ice cream, frozen meals, pizza, vegetables, berries',
|
||||
});
|
||||
category = await Category.create({
|
||||
name: 'Pantry Staples',
|
||||
description: 'Pasta, rice, sauces, oils, vinegar, spices, canned goods',
|
||||
});
|
||||
|
||||
const categories = await Category.findAll();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
32
tsc1877/task1/project/admin/db_seed/helloworld.js
Normal file
32
tsc1877/task1/project/admin/db_seed/helloworld.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('./model');
|
||||
|
||||
const User = sequelize.define(
|
||||
'User',
|
||||
{
|
||||
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
firstName: { type: DataTypes.STRING, allowNull: false },
|
||||
lastName: { type: DataTypes.STRING, allowNull: false },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
// create table
|
||||
await sequelize.sync();
|
||||
|
||||
let users = await User.findAll({ attributes: ['firstName'] });
|
||||
User.destroy({ truncate: true, cascade: true, force: true });
|
||||
|
||||
const user = await User.create({ firstName: 'John', lastName: 'Doe' });
|
||||
users = await User.findAll();
|
||||
|
||||
// await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
38
tsc1877/task1/project/admin/db_seed/item.js
Normal file
38
tsc1877/task1/project/admin/db_seed/item.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('./model');
|
||||
|
||||
const Item = sequelize.define(
|
||||
'Items',
|
||||
{
|
||||
item_id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
pid: { type: DataTypes.INTEGER },
|
||||
description: { type: DataTypes.STRING, allowNull: false },
|
||||
sold: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
await Item.drop();
|
||||
|
||||
await sequelize.sync();
|
||||
for (var j = 1; j <= 25; j++) {
|
||||
for (var i = 0; i < 10; i++) {
|
||||
await Item.create({
|
||||
// get remainder of i divided by 3
|
||||
// pid: (i % 25) + 1,
|
||||
pid: j,
|
||||
description: `test item ${i}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
14
tsc1877/task1/project/admin/db_seed/model.js
Normal file
14
tsc1877/task1/project/admin/db_seed/model.js
Normal file
@@ -0,0 +1,14 @@
|
||||
// dotenv to read .env file
|
||||
require('dotenv').config();
|
||||
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
|
||||
const { DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD } = process.env;
|
||||
|
||||
const sequelize = new Sequelize(DB_NAME, DB_USER, DB_PASSWORD, {
|
||||
host: DB_HOST,
|
||||
port: DB_PORT,
|
||||
dialect: 'mysql',
|
||||
});
|
||||
|
||||
module.exports = { sequelize };
|
86
tsc1877/task1/project/admin/db_seed/order.js
Normal file
86
tsc1877/task1/project/admin/db_seed/order.js
Normal file
@@ -0,0 +1,86 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('./model');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const Order = sequelize.define(
|
||||
'Orders',
|
||||
{
|
||||
order_id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
invoice_id: { type: DataTypes.STRING, allowNull: false },
|
||||
username: { type: DataTypes.STRING, allowNull: false },
|
||||
custom_id: { type: DataTypes.STRING, allowNull: false },
|
||||
amount: { type: DataTypes.STRING, allowNull: false },
|
||||
total_price: { type: DataTypes.DECIMAL, allowNull: false },
|
||||
currency_code: { type: DataTypes.STRING, allowNull: false },
|
||||
items: { type: DataTypes.STRING, allowNull: false },
|
||||
order_status: { type: DataTypes.STRING, allowNull: false, defaultValue: 'NOT_PAID' },
|
||||
salt: { type: DataTypes.STRING, allowNull: false },
|
||||
},
|
||||
{ timestamps: true },
|
||||
);
|
||||
|
||||
function genSalt() {
|
||||
return crypto.randomBytes(16).toString('hex');
|
||||
}
|
||||
|
||||
function createMD5HashWithSalt(inputString, salt) {
|
||||
// Prepend the salt to the inputString
|
||||
const saltedInput = salt + inputString;
|
||||
|
||||
// Proceed with the MD5 hash
|
||||
const hash = crypto.createHash('md5').update(saltedInput).digest('hex');
|
||||
|
||||
// Optionally, you might want to return both the hash and the salt
|
||||
// for storage, so you can verify the input against the hash later.
|
||||
return { salt, hash };
|
||||
}
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
const item_name = 'item_name';
|
||||
const quantity = parseInt('10');
|
||||
const unit_price = parseInt('1');
|
||||
const currency_code = 'HKD';
|
||||
const amount = parseInt(20);
|
||||
const total_price = parseInt(20);
|
||||
const email_name = 'cust1@vtkhmall.com';
|
||||
|
||||
// create table
|
||||
await Order.drop();
|
||||
|
||||
await sequelize.sync();
|
||||
|
||||
const order = await Order.create({
|
||||
invoice_id: crypto.randomUUID(),
|
||||
username: email_name,
|
||||
custom_id: createMD5HashWithSalt(
|
||||
JSON.stringify(
|
||||
[
|
||||
{ item_name, quantity, unit_price },
|
||||
{ item_name, quantity, unit_price },
|
||||
],
|
||||
total_price,
|
||||
currency_code,
|
||||
email_name,
|
||||
),
|
||||
genSalt(),
|
||||
)['hash'],
|
||||
amount,
|
||||
total_price,
|
||||
currency_code,
|
||||
items: JSON.stringify([
|
||||
{ item_name, quantity, unit_price },
|
||||
{ item_name, quantity, unit_price },
|
||||
]),
|
||||
order_status: 'NOT_PAID',
|
||||
salt: '12321',
|
||||
});
|
||||
orders = await Order.findAll();
|
||||
|
||||
// await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
36
tsc1877/task1/project/admin/db_seed/products.js
Normal file
36
tsc1877/task1/project/admin/db_seed/products.js
Normal file
@@ -0,0 +1,36 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('./model');
|
||||
|
||||
// const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
// host: 'mysql',
|
||||
// port: 3306,
|
||||
// dialect: 'mysql',
|
||||
// });
|
||||
|
||||
const Product = sequelize.define(
|
||||
'Products',
|
||||
{
|
||||
pid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
cid: { type: DataTypes.INTEGER, allowNull: false },
|
||||
name: { type: DataTypes.STRING, allowNull: false },
|
||||
description: { type: DataTypes.STRING, allowNull: false },
|
||||
price: { type: DataTypes.DECIMAL, allowNull: false },
|
||||
product_image: { type: DataTypes.STRING, allowNull: true, defaultValue: '' },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
await Product.drop();
|
||||
|
||||
await sequelize.sync();
|
||||
|
||||
// await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
86
tsc1877/task1/project/admin/db_seed/products_cid_1.js
Normal file
86
tsc1877/task1/project/admin/db_seed/products_cid_1.js
Normal file
@@ -0,0 +1,86 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('./model');
|
||||
|
||||
// const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
// host: 'mysql',
|
||||
// port: 3306,
|
||||
// dialect: 'mysql',
|
||||
// });
|
||||
|
||||
const Product = sequelize.define(
|
||||
'Products',
|
||||
{
|
||||
pid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
cid: { type: DataTypes.INTEGER, allowNull: false },
|
||||
name: { type: DataTypes.STRING, allowNull: false },
|
||||
product_image: { type: DataTypes.STRING, allowNull: false },
|
||||
description: { type: DataTypes.STRING, allowNull: false },
|
||||
price: { type: DataTypes.FLOAT, allowNull: false },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
// create table
|
||||
await sequelize.sync();
|
||||
|
||||
let products = [
|
||||
{
|
||||
cid: 1,
|
||||
name: 'French Baguette',
|
||||
description: 'A long, crusty loaf of French bread with a soft interior.',
|
||||
price: 5.5,
|
||||
product_image: 'BREAD1',
|
||||
},
|
||||
{
|
||||
cid: 1,
|
||||
name: 'Whole Wheat Bread',
|
||||
description: 'A nutritious bread made with whole wheat flour and grains.',
|
||||
price: 6.5,
|
||||
product_image: 'BREAD2',
|
||||
},
|
||||
{
|
||||
cid: 1,
|
||||
name: 'Croissants',
|
||||
description: 'Buttery, flaky pastries often enjoyed with coffee or tea.',
|
||||
price: 8.5,
|
||||
product_image: 'BREAD3',
|
||||
},
|
||||
{
|
||||
cid: 1,
|
||||
name: 'Donuts',
|
||||
description: 'Sweet, fried pastries with a variety of toppings and fillings.',
|
||||
price: 4.95,
|
||||
product_image: 'BREAD4',
|
||||
},
|
||||
{
|
||||
cid: 1,
|
||||
name: 'Whole Wheat Bread',
|
||||
description: 'A nutritious bread made with whole wheat flour and grains.',
|
||||
price: 6.5,
|
||||
product_image: 'BREAD2',
|
||||
},
|
||||
{
|
||||
cid: 1,
|
||||
name: 'Croissants',
|
||||
description: 'Buttery, flaky pastries often enjoyed with coffee or tea.',
|
||||
price: 8.5,
|
||||
product_image: 'BREAD3',
|
||||
},
|
||||
];
|
||||
|
||||
for (var i = 0; i < products.length; i++) {
|
||||
await Product.create(products[i]);
|
||||
}
|
||||
|
||||
const categories = await Product.findAll();
|
||||
|
||||
// await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
72
tsc1877/task1/project/admin/db_seed/products_cid_2.js
Normal file
72
tsc1877/task1/project/admin/db_seed/products_cid_2.js
Normal file
@@ -0,0 +1,72 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('./model');
|
||||
|
||||
// const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
// host: 'mysql',
|
||||
// port: 3306,
|
||||
// dialect: 'mysql',
|
||||
// });
|
||||
|
||||
const Product = sequelize.define(
|
||||
'Products',
|
||||
{
|
||||
pid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
cid: { type: DataTypes.INTEGER, allowNull: false },
|
||||
name: { type: DataTypes.STRING, allowNull: false },
|
||||
description: { type: DataTypes.STRING, allowNull: false },
|
||||
price: { type: DataTypes.DECIMAL, allowNull: false },
|
||||
product_image: { type: DataTypes.STRING, allowNull: false },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
// create table
|
||||
await sequelize.sync();
|
||||
|
||||
let products = [
|
||||
{
|
||||
cid: 2,
|
||||
name: 'Milk',
|
||||
description: 'A nutritious beverage made from the milk of cows, goats, or other mammals.',
|
||||
price: 5.5,
|
||||
product_image: 'DAIRY_1',
|
||||
},
|
||||
{
|
||||
cid: 2,
|
||||
name: 'Cheese',
|
||||
description: 'A versatile dairy product made from milk, available in a variety of flavors and textures.',
|
||||
price: 6.5,
|
||||
product_image: 'DAIRY_2',
|
||||
},
|
||||
{
|
||||
cid: 2,
|
||||
name: 'Yogurt',
|
||||
description: 'A creamy, fermented dairy product that comes in many flavors and styles.',
|
||||
price: 8.5,
|
||||
product_image: 'DAIRY_3',
|
||||
},
|
||||
{
|
||||
cid: 2,
|
||||
name: 'Butter',
|
||||
description: 'A dairy product made by churning cream, used for cooking and baking.',
|
||||
price: 4.95,
|
||||
product_image: 'DAIRY_4',
|
||||
},
|
||||
];
|
||||
|
||||
for (var i = 0; i < products.length; i++) {
|
||||
await Product.create(products[i]);
|
||||
}
|
||||
|
||||
const categories = await Product.findAll();
|
||||
|
||||
// await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
72
tsc1877/task1/project/admin/db_seed/products_cid_3.js
Normal file
72
tsc1877/task1/project/admin/db_seed/products_cid_3.js
Normal file
@@ -0,0 +1,72 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('./model');
|
||||
|
||||
// const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
// host: 'mysql',
|
||||
// port: 3306,
|
||||
// dialect: 'mysql',
|
||||
// });
|
||||
|
||||
const Product = sequelize.define(
|
||||
'Products',
|
||||
{
|
||||
pid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
cid: { type: DataTypes.INTEGER, allowNull: false },
|
||||
name: { type: DataTypes.STRING, allowNull: false },
|
||||
description: { type: DataTypes.STRING, allowNull: false },
|
||||
price: { type: DataTypes.DECIMAL, allowNull: false },
|
||||
product_image: { type: DataTypes.STRING, allowNull: true, defaultValue: '' },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
// create table
|
||||
await sequelize.sync();
|
||||
|
||||
let products = [
|
||||
{
|
||||
cid: 3,
|
||||
name: 'Chicken',
|
||||
description: 'A versatile and popular type of poultry, available in many cuts and preparations.',
|
||||
price: 9.95,
|
||||
product_image: 'MEAT1',
|
||||
},
|
||||
{
|
||||
cid: 3,
|
||||
name: 'Beef',
|
||||
description: 'A type of red meat that comes from cows, available in a variety of cuts and grades.',
|
||||
price: 13.5,
|
||||
product_image: 'MEAT2',
|
||||
},
|
||||
{
|
||||
cid: 3,
|
||||
name: 'Pork',
|
||||
description: 'A type of meat that comes from pigs, available in many cuts and preparations.',
|
||||
price: 27.8,
|
||||
product_image: 'MEAT3',
|
||||
},
|
||||
{
|
||||
cid: 3,
|
||||
name: 'Lamb',
|
||||
description: 'A type of red meat that comes from sheep, available in many cuts and preparations.',
|
||||
price: 25.95,
|
||||
product_image: 'MEAT4',
|
||||
},
|
||||
];
|
||||
|
||||
for (var i = 0; i < products.length; i++) {
|
||||
await Product.create(products[i]);
|
||||
}
|
||||
|
||||
const categories = await Product.findAll();
|
||||
|
||||
// await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
72
tsc1877/task1/project/admin/db_seed/products_cid_4.js
Normal file
72
tsc1877/task1/project/admin/db_seed/products_cid_4.js
Normal file
@@ -0,0 +1,72 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('./model');
|
||||
|
||||
// const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
// host: 'mysql',
|
||||
// port: 3306,
|
||||
// dialect: 'mysql',
|
||||
// });
|
||||
|
||||
const Product = sequelize.define(
|
||||
'Products',
|
||||
{
|
||||
pid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
cid: { type: DataTypes.INTEGER, allowNull: false },
|
||||
name: { type: DataTypes.STRING, allowNull: false },
|
||||
description: { type: DataTypes.STRING, allowNull: false },
|
||||
price: { type: DataTypes.DECIMAL, allowNull: false },
|
||||
product_image: { type: DataTypes.STRING, allowNull: false },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
// create table
|
||||
await sequelize.sync();
|
||||
|
||||
let products = [
|
||||
{
|
||||
cid: 4,
|
||||
name: 'Sliced Meats',
|
||||
description: 'Deli meats such as ham, turkey, salami, and roast beef, sliced to order.',
|
||||
price: 6.95,
|
||||
product_image: 'DELI_1',
|
||||
},
|
||||
{
|
||||
cid: 4,
|
||||
name: 'Cheese',
|
||||
description: 'A variety of cheeses, such as cheddar, Swiss, and mozzarella, sliced to order.',
|
||||
price: 7.5,
|
||||
product_image: 'DELI_2',
|
||||
},
|
||||
{
|
||||
cid: 4,
|
||||
name: 'Prepared Salads',
|
||||
description: 'Salads such as pasta salad, potato salad, and coleslaw, made fresh in-store.',
|
||||
price: 8.5,
|
||||
product_image: 'DELI_3',
|
||||
},
|
||||
{
|
||||
cid: 4,
|
||||
name: 'Rotisserie Chicken',
|
||||
description: 'Whole chickens that have been seasoned and roasted in-store, ready to take home and serve.',
|
||||
price: 7.5,
|
||||
product_image: 'DELI_4',
|
||||
},
|
||||
];
|
||||
|
||||
for (var i = 0; i < products.length; i++) {
|
||||
await Product.create(products[i]);
|
||||
}
|
||||
|
||||
const categories = await Product.findAll();
|
||||
|
||||
// await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
75
tsc1877/task1/project/admin/db_seed/products_cid_5.js
Normal file
75
tsc1877/task1/project/admin/db_seed/products_cid_5.js
Normal file
@@ -0,0 +1,75 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('./model');
|
||||
|
||||
// const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
// host: 'mysql',
|
||||
// port: 3306,
|
||||
// dialect: 'mysql',
|
||||
// });
|
||||
|
||||
const Product = sequelize.define(
|
||||
'Products',
|
||||
{
|
||||
pid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
cid: { type: DataTypes.INTEGER, allowNull: false },
|
||||
name: { type: DataTypes.STRING, allowNull: false },
|
||||
product_image: { type: DataTypes.STRING, allowNull: false },
|
||||
description: { type: DataTypes.STRING, allowNull: false },
|
||||
price: { type: DataTypes.DECIMAL, allowNull: false },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
// create table
|
||||
await sequelize.sync();
|
||||
|
||||
let products = [
|
||||
{
|
||||
cid: 5,
|
||||
name: 'Frozen Vegetables',
|
||||
description: 'A variety of vegetables, such as peas, corn, and broccoli, frozen at peak freshness.',
|
||||
price: 5.5,
|
||||
product_image: 'FROZEN_1',
|
||||
},
|
||||
{
|
||||
cid: 5,
|
||||
name: 'Frozen Seafood',
|
||||
description: 'A variety of seafood, such as shrimp, fish, and scallops, frozen for freshness and convenience.',
|
||||
|
||||
price: 6.5,
|
||||
product_image: 'FROZEN_2',
|
||||
},
|
||||
{
|
||||
cid: 5,
|
||||
name: 'Frozen Meals',
|
||||
description: 'Pre-made meals such as pizza, lasagna, and stir-fry, available for quick and easy dinners.',
|
||||
|
||||
price: 8.5,
|
||||
product_image: 'FROZEN_3',
|
||||
},
|
||||
{
|
||||
cid: 5,
|
||||
name: 'Frozen Fruits',
|
||||
description: 'A variety of fruits, such as berries, mango, and pineapple, frozen at peak freshness.',
|
||||
|
||||
price: 4.95,
|
||||
product_image: 'FROZEN_4',
|
||||
},
|
||||
];
|
||||
|
||||
for (var i = 0; i < products.length; i++) {
|
||||
await Product.create(products[i]);
|
||||
}
|
||||
|
||||
const categories = await Product.findAll();
|
||||
|
||||
// await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
86
tsc1877/task1/project/admin/db_seed/products_cid_6.js
Normal file
86
tsc1877/task1/project/admin/db_seed/products_cid_6.js
Normal file
@@ -0,0 +1,86 @@
|
||||
const { Sequelize, DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('./model');
|
||||
|
||||
// const sequelize = new Sequelize('app_db', 'db_user', 'db_user_pass', {
|
||||
// host: 'mysql',
|
||||
// port: 3306,
|
||||
// dialect: 'mysql',
|
||||
// });
|
||||
|
||||
const Product = sequelize.define(
|
||||
'Products',
|
||||
{
|
||||
pid: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, unique: true },
|
||||
cid: { type: DataTypes.INTEGER, allowNull: false },
|
||||
name: { type: DataTypes.STRING, allowNull: false },
|
||||
product_image: { type: DataTypes.STRING, allowNull: false },
|
||||
description: { type: DataTypes.STRING, allowNull: false },
|
||||
price: { type: DataTypes.DECIMAL, allowNull: false },
|
||||
},
|
||||
{ timestamps: false },
|
||||
);
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
await sequelize.authenticate();
|
||||
console.log('Connection has been established successfully.');
|
||||
|
||||
// create table
|
||||
await sequelize.sync();
|
||||
|
||||
let products = [
|
||||
{
|
||||
cid: 6,
|
||||
name: 'Pasta',
|
||||
description: 'A variety of pasta shapes and types, such as spaghetti, macaroni, and lasagna noodles.',
|
||||
price: 5.5,
|
||||
product_image: 'PANTRY_1',
|
||||
},
|
||||
{
|
||||
cid: 6,
|
||||
name: 'Rice',
|
||||
description: 'A variety of rice types, such as white rice, brown rice, and jasmine rice.',
|
||||
price: 6.5,
|
||||
product_image: 'PANTRY_2',
|
||||
},
|
||||
{
|
||||
cid: 6,
|
||||
name: 'Canned Beans',
|
||||
description: 'A variety of beans, such as black beans, kidney beans, and chickpeas, canned for convenience.',
|
||||
price: 8.5,
|
||||
product_image: 'PANTRY_3',
|
||||
},
|
||||
{
|
||||
cid: 6,
|
||||
name: 'Canned Tomatoes',
|
||||
description: 'A variety of canned tomatoes, such as diced tomatoes, crushed tomatoes, and tomato sauce.',
|
||||
price: 4.95,
|
||||
product_image: 'PANTRY_4',
|
||||
},
|
||||
{
|
||||
cid: 6,
|
||||
name: 'Canned Beans',
|
||||
description: 'A variety of beans, such as black beans, kidney beans, and chickpeas, canned for convenience.',
|
||||
price: 8.5,
|
||||
product_image: 'PANTRY_3',
|
||||
},
|
||||
{
|
||||
cid: 6,
|
||||
name: 'Canned Tomatoes',
|
||||
description: 'A variety of canned tomatoes, such as diced tomatoes, crushed tomatoes, and tomato sauce.',
|
||||
price: 4.95,
|
||||
product_image: 'PANTRY_4',
|
||||
},
|
||||
];
|
||||
|
||||
for (var i = 0; i < products.length; i++) {
|
||||
await Product.create(products[i]);
|
||||
}
|
||||
|
||||
const categories = await Product.findAll();
|
||||
|
||||
// await sequelize.close();
|
||||
} catch (error) {
|
||||
console.error('Unable to connect to the database:', error);
|
||||
}
|
||||
})();
|
32
tsc1877/task1/project/admin/db_seed/seed_all.js
Normal file
32
tsc1877/task1/project/admin/db_seed/seed_all.js
Normal file
@@ -0,0 +1,32 @@
|
||||
function delay(time_ms) {
|
||||
return new Promise((res, rej) => {
|
||||
setTimeout(() => {
|
||||
res();
|
||||
}, time_ms);
|
||||
});
|
||||
}
|
||||
|
||||
(async () => {
|
||||
await require('./helloworld');
|
||||
await delay(100);
|
||||
|
||||
await require('./categories');
|
||||
await delay(100);
|
||||
|
||||
await require('./products');
|
||||
await delay(100);
|
||||
|
||||
await require('./products_cid_1');
|
||||
await require('./products_cid_2');
|
||||
await require('./products_cid_3');
|
||||
await require('./products_cid_4');
|
||||
await require('./products_cid_5');
|
||||
await require('./products_cid_6');
|
||||
|
||||
await require('./auth');
|
||||
|
||||
await require('./item');
|
||||
await require('./order');
|
||||
|
||||
console.log('done');
|
||||
})();
|
Reference in New Issue
Block a user