From abaa940a08768f1ad2a1c8e50b4fedaf5df751e7 Mon Sep 17 00:00:00 2001 From: mohjaps Date: Thu, 13 Oct 2022 08:02:48 +0300 Subject: [PATCH 01/12] Init Transactions, Reviews and Users Models Related #4 --- server/models/index.ts | 0 server/models/reviews.ts | 70 +++++++++++++++++++++++++++++++ server/models/transactions.ts | 54 ++++++++++++++++++++++++ server/models/users.ts | 79 +++++++++++++++++++++++++++++++++++ 4 files changed, 203 insertions(+) delete mode 100644 server/models/index.ts create mode 100644 server/models/reviews.ts create mode 100644 server/models/transactions.ts create mode 100644 server/models/users.ts diff --git a/server/models/index.ts b/server/models/index.ts deleted file mode 100644 index e69de29..0000000 diff --git a/server/models/reviews.ts b/server/models/reviews.ts new file mode 100644 index 0000000..c570c29 --- /dev/null +++ b/server/models/reviews.ts @@ -0,0 +1,70 @@ +import { + Model, + InferAttributes, + InferCreationAttributes, + CreationOptional, + DataTypes, +} from 'sequelize'; +import sequelize from '../database/connection'; + +export class Reviews extends Model< +InferAttributes, +InferCreationAttributes +> { + declare id: CreationOptional; + + declare title?: string; + + declare description?: Text; + + declare points?: number; + + declare is_shown?: boolean; + + declare creation_date?: Date; + + declare user_id?: number; +} + +Reviews.init( + { + id: { + type: DataTypes.GUID, + autoIncrement: true, + primaryKey: true, + }, + title: { + type: DataTypes.STRING(255), + allowNull: false, + }, + description: { + type: DataTypes.TEXT, + allowNull: true, + }, + points: { + type: DataTypes.NUMBER, + allowNull: false, + validate: { + min: 1, + max: 5, + }, + }, + is_shown: { + type: DataTypes.BOOLEAN, + allowNull: false, + }, + creation_date: { + type: DataTypes.DATE, + defaultValue: new Date(), + }, + user_id: { + type: DataTypes.NUMBER, + allowNull: false, + }, + }, + { + sequelize, + }, +); + +export default Reviews; diff --git a/server/models/transactions.ts b/server/models/transactions.ts new file mode 100644 index 0000000..2108aac --- /dev/null +++ b/server/models/transactions.ts @@ -0,0 +1,54 @@ +import { + Model, + InferAttributes, + InferCreationAttributes, + CreationOptional, + DataTypes, +} from "sequelize"; +import sequelize from "../database/connection"; + +export class Transactions extends Model< +InferAttributes, +InferCreationAttributes +> { + declare id: CreationOptional; + + declare title?: string; + + declare description?: Text; + + declare creation_date?: Date; + + declare user_id?: number; +} + +Transactions.init( + { + id: { + type: DataTypes.GUID, + autoIncrement: true, + primaryKey: true, + }, + title: { + type: DataTypes.STRING(255), + allowNull: false, + }, + description: { + type: DataTypes.TEXT, + allowNull: true, + }, + creation_date: { + type: DataTypes.DATE, + defaultValue: new Date(), + }, + user_id: { + type: DataTypes.NUMBER, + allowNull: false, + }, + }, + { + sequelize, + } +); + +export default Transactions; diff --git a/server/models/users.ts b/server/models/users.ts new file mode 100644 index 0000000..593d003 --- /dev/null +++ b/server/models/users.ts @@ -0,0 +1,79 @@ +import { + Model, + InferAttributes, + InferCreationAttributes, + CreationOptional, + DataTypes, +} from 'sequelize'; +import sequelize from '../database/connection'; + +export class Users extends Model< +InferAttributes, +InferCreationAttributes +> { + declare id: CreationOptional; + + declare first_name?: string; + + declare last_name?: string; + + declare email?: string; + + declare phone_number?: string; + + declare creation_date?: Date; + + declare roles?: 'ADMIN' | 'USER'; + + declare hased_password?: string; +} + +Users.init( + { + id: { + type: DataTypes.GUID, + autoIncrement: true, + primaryKey: true, + }, + first_name: { + type: DataTypes.STRING(100), + allowNull: false, + }, + last_name: { + type: DataTypes.STRING(100), + allowNull: false, + }, + email: { + type: DataTypes.STRING(100), + allowNull: true, + validate: { + isEmail: true, + }, + }, + phone_number: { + type: DataTypes.STRING(14), + unique: true, + allowNull: false, + }, + creation_date: { + type: DataTypes.DATE, + defaultValue: new Date(), + }, + roles: { + type: DataTypes.ENUM('ADMIN', 'USER'), + allowNull: false, + }, + hased_password: { + type: DataTypes.STRING(64), + validate: { + is: /^[0-9a-f]{64}$/i, + }, + allowNull: false, + }, + }, + { + sequelize, + }, +); + +export default Users; From 61ec2ca8e2769fe2d1c8510954428f7ac1458a7e Mon Sep 17 00:00:00 2001 From: mohjaps Date: Thu, 13 Oct 2022 12:32:13 +0300 Subject: [PATCH 02/12] Change Class To Interface Related #44 --- server/models/reviews.ts | 34 ++++++++++++++++----------------- server/models/transactions.ts | 32 +++++++++++++++---------------- server/models/users.ts | 36 +++++++++++++++++------------------ 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/server/models/reviews.ts b/server/models/reviews.ts index c570c29..88a0671 100644 --- a/server/models/reviews.ts +++ b/server/models/reviews.ts @@ -5,31 +5,34 @@ import { CreationOptional, DataTypes, } from 'sequelize'; -import sequelize from '../database/connection'; +import sequelize from '../database/config/connection'; -export class Reviews extends Model< -InferAttributes, -InferCreationAttributes -> { - declare id: CreationOptional; +interface ReviewsModel + extends Model< + InferAttributes, + InferCreationAttributes + > { + id: CreationOptional - declare title?: string; + title?: string - declare description?: Text; + description?: Text - declare points?: number; + points?: number - declare is_shown?: boolean; + is_shown?: boolean - declare creation_date?: Date; + creation_date?: Date - declare user_id?: number; + user_id?: number } -Reviews.init( +const Reviews = sequelize.define( + 'Reviews', { id: { - type: DataTypes.GUID, + type: DataTypes.UUID, + defaultValue: DataTypes.UUIDV4, autoIncrement: true, primaryKey: true, }, @@ -62,9 +65,6 @@ Reviews.init( allowNull: false, }, }, - { - sequelize, - }, ); export default Reviews; diff --git a/server/models/transactions.ts b/server/models/transactions.ts index 2108aac..e95c0e5 100644 --- a/server/models/transactions.ts +++ b/server/models/transactions.ts @@ -4,28 +4,31 @@ import { InferCreationAttributes, CreationOptional, DataTypes, -} from "sequelize"; -import sequelize from "../database/connection"; +} from 'sequelize'; +import sequelize from '../database/config/connection'; -export class Transactions extends Model< -InferAttributes, -InferCreationAttributes -> { - declare id: CreationOptional; +interface TransactionsModel + extends Model< + InferAttributes, + InferCreationAttributes + > { + id: CreationOptional - declare title?: string; + title?: string - declare description?: Text; + description?: Text - declare creation_date?: Date; + creation_date?: Date - declare user_id?: number; + user_id?: number } -Transactions.init( +const Transactions = sequelize.define( + 'Transactions', { id: { - type: DataTypes.GUID, + type: DataTypes.UUID, + defaultValue: DataTypes.UUIDV4, autoIncrement: true, primaryKey: true, }, @@ -46,9 +49,6 @@ Transactions.init( allowNull: false, }, }, - { - sequelize, - } ); export default Transactions; diff --git a/server/models/users.ts b/server/models/users.ts index 593d003..7a69712 100644 --- a/server/models/users.ts +++ b/server/models/users.ts @@ -5,33 +5,36 @@ import { CreationOptional, DataTypes, } from 'sequelize'; -import sequelize from '../database/connection'; +import sequelize from '../database/config/connection'; -export class Users extends Model< -InferAttributes, -InferCreationAttributes -> { - declare id: CreationOptional; +interface UsersModel + extends Model< + InferAttributes, + InferCreationAttributes + > { + id: CreationOptional - declare first_name?: string; + first_name?: string - declare last_name?: string; + last_name?: string - declare email?: string; + email?: string - declare phone_number?: string; + phone_number?: string - declare creation_date?: Date; + creation_date?: Date - declare roles?: 'ADMIN' | 'USER'; + roles?: 'ADMIN' | 'USER' - declare hased_password?: string; + hased_password?: string } -Users.init( +const Users = sequelize.define( + 'Transactions', { id: { - type: DataTypes.GUID, + type: DataTypes.UUID, + defaultValue: DataTypes.UUIDV4, autoIncrement: true, primaryKey: true, }, @@ -71,9 +74,6 @@ Users.init( allowNull: false, }, }, - { - sequelize, - }, ); export default Users; From e709d227c6798d8d9f177063c61d4d2d58a3ee15 Mon Sep 17 00:00:00 2001 From: mohjaps Date: Thu, 13 Oct 2022 14:32:48 +0300 Subject: [PATCH 03/12] fake data --- server/database/config/build.ts | 18 +- server/database/config/fakeData.ts | 469 +++++++++++++++++++++++++++++ server/models/index.ts | 6 + server/models/reviews.ts | 10 +- server/models/transactions.ts | 4 +- server/models/users.ts | 23 +- 6 files changed, 507 insertions(+), 23 deletions(-) create mode 100644 server/database/config/fakeData.ts create mode 100644 server/models/index.ts diff --git a/server/database/config/build.ts b/server/database/config/build.ts index 6c4fbe1..b3c6a12 100644 --- a/server/database/config/build.ts +++ b/server/database/config/build.ts @@ -1,6 +1,18 @@ -import sequelize from "./connection"; - +import sequelize from './connection'; +import { + reviews, transactions, users, +} from './fakeData'; +import { + Reviews, Transactions, Users, +} from '../../models/index'; const dbConnect = () => sequelize.sync(); -export { dbConnect } \ No newline at end of file +const insertDB = async () => { + await sequelize.sync({ force: true }); + await Users.bulkCreate(users); + await Transactions.bulkCreate(transactions); + await Reviews.bulkCreate(reviews); +}; +insertDB(); +export default dbConnect; diff --git a/server/database/config/fakeData.ts b/server/database/config/fakeData.ts new file mode 100644 index 0000000..1774f3d --- /dev/null +++ b/server/database/config/fakeData.ts @@ -0,0 +1,469 @@ +const users = [{ + id: 1, + first_name: 'Jules', + last_name: 'Cotte', + email: 'jcotte0@people.com.cn', + phone_number: '318-530-6030', + creation_date: '12/2/2021', + roles: 'ADMIN', + hased_password: 'eDuvQFk2tKR', +}, { + id: 2, + first_name: 'Gwen', + last_name: 'Belt', + email: 'gbelt1@thetimes.co.uk', + phone_number: '235-783-1177', + creation_date: '2/16/2022', + roles: 'USER', + hased_password: 'j1Lwy1VL3k', +}, { + id: 3, + first_name: 'Trumann', + last_name: 'Lobe', + email: 'tlobe2@angelfire.com', + phone_number: '498-722-9258', + creation_date: '4/8/2022', + roles: 'USER', + hased_password: 'UuXPw5W7H', +}, { + id: 4, + first_name: 'Meta', + last_name: 'Gravey', + email: 'mgravey3@slideshare.net', + phone_number: '172-408-5906', + creation_date: '1/8/2022', + roles: 'USER', + hased_password: '3ZzMhbjfY6', +}, { + id: 5, + first_name: 'Chryste', + last_name: 'Scogin', + email: 'cscogin4@nytimes.com', + phone_number: '910-220-7086', + creation_date: '6/29/2022', + roles: 'USER', + hased_password: '1edtRkJrJz1', +}, { + id: 6, + first_name: 'Bettye', + last_name: 'Frail', + email: 'bfrail5@google.com.br', + phone_number: '178-978-2984', + creation_date: '11/29/2021', + roles: 'USER', + hased_password: 'FBL5ZQ8', +}, { + id: 7, + first_name: 'Barbi', + last_name: 'Justis', + email: 'bjustis6@state.gov', + phone_number: '153-758-3576', + creation_date: '9/29/2022', + roles: 'USER', + hased_password: 'rqynGoZr6XJ1', +}, { + id: 8, + first_name: 'Ebba', + last_name: 'Saltsberg', + email: 'esaltsberg7@naver.com', + phone_number: '746-342-8706', + creation_date: '1/17/2022', + roles: 'USER', + hased_password: 'NOj9CbSR', +}, { + id: 9, + first_name: 'Cinnamon', + last_name: 'McGairl', + email: 'cmcgairl8@livejournal.com', + phone_number: '839-484-5210', + creation_date: '3/21/2022', + roles: 'USER', + hased_password: 'a82tTF', +}, { + id: 10, + first_name: 'Cordell', + last_name: 'Shannahan', + email: 'cshannahan9@wunderground.com', + phone_number: '916-108-1812', + creation_date: '7/16/2022', + roles: 'USER', + hased_password: 'VWqe6ZR', +}, { + id: 11, + first_name: 'Elisha', + last_name: 'Nadin', + email: 'enadina@php.net', + phone_number: '900-620-7479', + creation_date: '3/27/2022', + roles: 'USER', + hased_password: 'CfBoa3bYZkPr', +}, { + id: 12, + first_name: 'Maxi', + last_name: 'Bront', + email: 'mbrontb@phpbb.com', + phone_number: '959-720-9384', + creation_date: '9/3/2022', + roles: 'USER', + hased_password: 'bVVXcX3nLF', +}, { + id: 13, + first_name: 'Star', + last_name: 'Scoggans', + email: 'sscoggansc@noaa.gov', + phone_number: '521-649-4149', + creation_date: '3/22/2022', + roles: 'USER', + hased_password: 'D5PQW7u7jv3', +}, { + id: 14, + first_name: 'Eben', + last_name: 'Johnigan', + email: 'ejohnigand@blinklist.com', + phone_number: '148-222-5388', + creation_date: '1/11/2022', + roles: 'USER', + hased_password: 'bVDwvHM', +}, { + id: 15, + first_name: 'Aimil', + last_name: 'Binks', + email: 'abinkse@flickr.com', + phone_number: '907-611-5915', + creation_date: '11/26/2021', + roles: 'USER', + hased_password: 'OT3k2suBFF9X', +}, { + id: 16, + first_name: 'Lyn', + last_name: 'Bridge', + email: 'lbridgef@columbia.edu', + phone_number: '813-752-6434', + creation_date: '11/4/2021', + roles: 'USER', + hased_password: 'L1g4CHQWq5', +}, { + id: 17, + first_name: 'Ana', + last_name: 'Jayme', + email: 'ajaymeg@nifty.com', + phone_number: '588-244-3150', + creation_date: '4/28/2022', + roles: 'USER', + hased_password: 'ojldRgoVO', +}, { + id: 18, + first_name: 'Barnard', + last_name: 'Ivanyushkin', + email: 'bivanyushkinh@behance.net', + phone_number: '390-816-5923', + creation_date: '7/2/2022', + roles: 'USER', + hased_password: 'zBZRkc7qlYA', +}, { + id: 19, + first_name: 'Jeanelle', + last_name: 'Stranio', + email: 'jstranioi@ibm.com', + phone_number: '405-527-5827', + creation_date: '6/27/2022', + roles: 'USER', + hased_password: 'kvd7ziyp', +}, { + id: 20, + first_name: 'Gwenneth', + last_name: 'Allridge', + email: 'gallridgej@latimes.com', + phone_number: '330-739-1479', + creation_date: '1/6/2022', + roles: 'USER', + hased_password: 'zgGeNhGc', +}]; + +const reviews = [{ + id: 1, + title: 'Financial Advisor', + description: 'Nullam porttitor lacus at turpis. Donec posuere metus vitae ipsum. Aliquam non mauris.\n\nMorbi non lectus. Aliquam sit amet diam in magna bibendum imperdiet. Nullam orci pede, venenatis non, sodales sed, tincidunt eu, felis.\n\nFusce posuere felis sed lacus. Morbi sem mauris, laoreet ut, rhoncus aliquet, pulvinar sed, nisl. Nunc rhoncus dui vel sem.', + points: 2, + is_shown: false, + creation_date: '9/13/2022', + user_id: 15, +}, { + id: 2, + title: 'Project Manager', + description: 'Aliquam quis turpis eget elit sodales scelerisque. Mauris sit amet eros. Suspendisse accumsan tortor quis turpis.', + points: 2, + is_shown: false, + creation_date: '5/20/2022', + user_id: 14, +}, { + id: 3, + title: 'Software Engineer I', + description: 'Vestibulum ac est lacinia nisi venenatis tristique. Fusce congue, diam id ornare imperdiet, sapien urna pretium nisl, ut volutpat sapien arcu sed augue. Aliquam erat volutpat.\n\nIn congue. Etiam justo. Etiam pretium iaculis justo.\n\nIn hac habitasse platea dictumst. Etiam faucibus cursus urna. Ut tellus.', + points: 0, + is_shown: false, + creation_date: '3/25/2022', + user_id: 1, +}, { + id: 4, + title: 'VP Product Management', + description: 'Integer tincidunt ante vel ipsum. Praesent blandit lacinia erat. Vestibulum sed magna at nunc commodo placerat.\n\nPraesent blandit. Nam nulla. Integer pede justo, lacinia eget, tincidunt eget, tempus vel, pede.\n\nMorbi porttitor lorem id ligula. Suspendisse ornare consequat lectus. In est risus, auctor sed, tristique in, tempus sit amet, sem.', + points: 2, + is_shown: false, + creation_date: '2/10/2022', + user_id: 20, +}, { + id: 5, + title: 'Web Designer IV', + description: 'Cras mi pede, malesuada in, imperdiet et, commodo vulputate, justo. In blandit ultrices enim. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\n\nProin interdum mauris non ligula pellentesque ultrices. Phasellus id sapien in sapien iaculis congue. Vivamus metus arcu, adipiscing molestie, hendrerit at, vulputate vitae, nisl.', + points: 0, + is_shown: true, + creation_date: '12/13/2021', + user_id: 14, +}, { + id: 6, + title: 'Assistant Media Planner', + description: 'In quis justo. Maecenas rhoncus aliquam lacus. Morbi quis tortor id nulla ultrices aliquet.\n\nMaecenas leo odio, condimentum id, luctus nec, molestie sed, justo. Pellentesque viverra pede ac diam. Cras pellentesque volutpat dui.', + points: 4, + is_shown: true, + creation_date: '11/1/2021', + user_id: 20, +}, { + id: 7, + title: 'Occupational Therapist', + description: 'Cras non velit nec nisi vulputate nonummy. Maecenas tincidunt lacus at velit. Vivamus vel nulla eget eros elementum pellentesque.', + points: 2, + is_shown: false, + creation_date: '12/20/2021', + user_id: 10, +}, { + id: 8, + title: 'Data Coordiator', + description: 'Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.\n\nPhasellus sit amet erat. Nulla tempus. Vivamus in felis eu sapien cursus vestibulum.\n\nProin eu mi. Nulla ac enim. In tempor, turpis nec euismod scelerisque, quam turpis adipiscing lorem, vitae mattis nibh ligula nec sem.', + points: 3, + is_shown: true, + creation_date: '8/12/2022', + user_id: 3, +}, { + id: 9, + title: 'Geologist I', + description: 'Nullam porttitor lacus at turpis. Donec posuere metus vitae ipsum. Aliquam non mauris.', + points: 2, + is_shown: true, + creation_date: '2/12/2022', + user_id: 15, +}, { + id: 10, + title: 'Web Developer I', + description: 'Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vivamus vestibulum sagittis sapien. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.\n\nEtiam vel augue. Vestibulum rutrum rutrum neque. Aenean auctor gravida sem.', + points: 0, + is_shown: true, + creation_date: '6/23/2022', + user_id: 17, +}, { + id: 11, + title: 'Product Engineer', + description: 'Duis bibendum, felis sed interdum venenatis, turpis enim blandit mi, in porttitor pede justo eu massa. Donec dapibus. Duis at velit eu est congue elementum.', + points: 4, + is_shown: false, + creation_date: '6/19/2022', + user_id: 3, +}, { + id: 12, + title: 'Sales Representative', + description: 'Maecenas tristique, est et tempus semper, est quam pharetra magna, ac consequat metus sapien ut nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris viverra diam vitae quam. Suspendisse potenti.\n\nNullam porttitor lacus at turpis. Donec posuere metus vitae ipsum. Aliquam non mauris.\n\nMorbi non lectus. Aliquam sit amet diam in magna bibendum imperdiet. Nullam orci pede, venenatis non, sodales sed, tincidunt eu, felis.', + points: 1, + is_shown: true, + creation_date: '2/9/2022', + user_id: 12, +}, { + id: 13, + title: 'Senior Quality Engineer', + description: 'Mauris enim leo, rhoncus sed, vestibulum sit amet, cursus id, turpis. Integer aliquet, massa id lobortis convallis, tortor risus dapibus augue, vel accumsan tellus nisi eu orci. Mauris lacinia sapien quis libero.', + points: 3, + is_shown: false, + creation_date: '10/12/2022', + user_id: 8, +}, { + id: 14, + title: 'Senior Cost Accountant', + description: 'Sed sagittis. Nam congue, risus semper porta volutpat, quam pede lobortis ligula, sit amet eleifend pede libero quis orci. Nullam molestie nibh in lectus.\n\nPellentesque at nulla. Suspendisse potenti. Cras in purus eu magna vulputate luctus.', + points: 5, + is_shown: false, + creation_date: '8/21/2022', + user_id: 16, +}, { + id: 15, + title: 'Nurse', + description: 'Maecenas ut massa quis augue luctus tincidunt. Nulla mollis molestie lorem. Quisque ut erat.', + points: 5, + is_shown: false, + creation_date: '8/25/2022', + user_id: 7, +}, { + id: 16, + title: 'Assistant Manager', + description: 'Aenean lectus. Pellentesque eget nunc. Donec quis orci eget orci vehicula condimentum.\n\nCurabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.', + points: 2, + is_shown: false, + creation_date: '10/29/2021', + user_id: 18, +}, { + id: 17, + title: 'Information Systems Manager', + description: 'Integer ac leo. Pellentesque ultrices mattis odio. Donec vitae nisi.', + points: 1, + is_shown: true, + creation_date: '10/5/2022', + user_id: 13, +}, { + id: 18, + title: 'Statistician I', + description: 'Fusce consequat. Nulla nisl. Nunc nisl.\n\nDuis bibendum, felis sed interdum venenatis, turpis enim blandit mi, in porttitor pede justo eu massa. Donec dapibus. Duis at velit eu est congue elementum.', + points: 2, + is_shown: false, + creation_date: '7/7/2022', + user_id: 13, +}, { + id: 19, + title: 'Senior Developer', + description: 'Maecenas tristique, est et tempus semper, est quam pharetra magna, ac consequat metus sapien ut nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris viverra diam vitae quam. Suspendisse potenti.', + points: 0, + is_shown: true, + creation_date: '3/3/2022', + user_id: 8, +}, { + id: 20, + title: 'General Manager', + description: 'Nam ultrices, libero non mattis pulvinar, nulla pede ullamcorper augue, a suscipit nulla elit ac nulla. Sed vel enim sit amet nunc viverra dapibus. Nulla suscipit ligula in lacus.', + points: 3, + is_shown: true, + creation_date: '10/30/2021', + user_id: 4, +}]; + +const transactions = [{ + id: 1, + title: 'Developer I', + description: 'Maecenas leo odio, condimentum id, luctus nec, molestie sed, justo. Pellentesque viverra pede ac diam. Cras pellentesque volutpat dui.\n\nMaecenas tristique, est et tempus semper, est quam pharetra magna, ac consequat metus sapien ut nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris viverra diam vitae quam. Suspendisse potenti.', + creation_date: '4/8/2022', + user_id: 8, +}, { + id: 2, + title: 'Senior Editor', + description: 'Aenean lectus. Pellentesque eget nunc. Donec quis orci eget orci vehicula condimentum.\n\nCurabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.', + creation_date: '1/11/2022', + user_id: 9, +}, { + id: 3, + title: 'Graphic Designer', + description: 'Duis bibendum, felis sed interdum venenatis, turpis enim blandit mi, in porttitor pede justo eu massa. Donec dapibus. Duis at velit eu est congue elementum.\n\nIn hac habitasse platea dictumst. Morbi vestibulum, velit id pretium iaculis, diam erat fermentum justo, nec condimentum neque sapien placerat ante. Nulla justo.\n\nAliquam quis turpis eget elit sodales scelerisque. Mauris sit amet eros. Suspendisse accumsan tortor quis turpis.', + creation_date: '2/4/2022', + user_id: 20, +}, { + id: 4, + title: 'Analog Circuit Design manager', + description: 'Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.\n\nPhasellus sit amet erat. Nulla tempus. Vivamus in felis eu sapien cursus vestibulum.\n\nProin eu mi. Nulla ac enim. In tempor, turpis nec euismod scelerisque, quam turpis adipiscing lorem, vitae mattis nibh ligula nec sem.', + creation_date: '4/17/2022', + user_id: 17, +}, { + id: 5, + title: 'Librarian', + description: 'Nullam porttitor lacus at turpis. Donec posuere metus vitae ipsum. Aliquam non mauris.\n\nMorbi non lectus. Aliquam sit amet diam in magna bibendum imperdiet. Nullam orci pede, venenatis non, sodales sed, tincidunt eu, felis.\n\nFusce posuere felis sed lacus. Morbi sem mauris, laoreet ut, rhoncus aliquet, pulvinar sed, nisl. Nunc rhoncus dui vel sem.', + creation_date: '11/1/2021', + user_id: 4, +}, { + id: 6, + title: 'Librarian', + description: 'Aliquam quis turpis eget elit sodales scelerisque. Mauris sit amet eros. Suspendisse accumsan tortor quis turpis.\n\nSed ante. Vivamus tortor. Duis mattis egestas metus.', + creation_date: '9/1/2022', + user_id: 13, +}, { + id: 7, + title: 'Actuary', + description: 'Duis bibendum. Morbi non quam nec dui luctus rutrum. Nulla tellus.\n\nIn sagittis dui vel nisl. Duis ac nibh. Fusce lacus purus, aliquet at, feugiat non, pretium quis, lectus.', + creation_date: '7/5/2022', + user_id: 16, +}, { + id: 8, + title: 'Accountant III', + description: 'Suspendisse potenti. In eleifend quam a odio. In hac habitasse platea dictumst.\n\nMaecenas ut massa quis augue luctus tincidunt. Nulla mollis molestie lorem. Quisque ut erat.', + creation_date: '4/24/2022', + user_id: 6, +}, { + id: 9, + title: 'Cost Accountant', + description: 'Proin interdum mauris non ligula pellentesque ultrices. Phasellus id sapien in sapien iaculis congue. Vivamus metus arcu, adipiscing molestie, hendrerit at, vulputate vitae, nisl.', + creation_date: '7/7/2022', + user_id: 6, +}, { + id: 10, + title: 'Senior Financial Analyst', + description: 'Duis bibendum. Morbi non quam nec dui luctus rutrum. Nulla tellus.', + creation_date: '1/16/2022', + user_id: 11, +}, { + id: 11, + title: 'Research Assistant I', + description: 'Morbi porttitor lorem id ligula. Suspendisse ornare consequat lectus. In est risus, auctor sed, tristique in, tempus sit amet, sem.\n\nFusce consequat. Nulla nisl. Nunc nisl.\n\nDuis bibendum, felis sed interdum venenatis, turpis enim blandit mi, in porttitor pede justo eu massa. Donec dapibus. Duis at velit eu est congue elementum.', + creation_date: '8/13/2022', + user_id: 17, +}, { + id: 12, + title: 'Internal Auditor', + description: 'Integer ac leo. Pellentesque ultrices mattis odio. Donec vitae nisi.\n\nNam ultrices, libero non mattis pulvinar, nulla pede ullamcorper augue, a suscipit nulla elit ac nulla. Sed vel enim sit amet nunc viverra dapibus. Nulla suscipit ligula in lacus.', + creation_date: '3/6/2022', + user_id: 12, +}, { + id: 13, + title: 'Internal Auditor', + description: 'Quisque porta volutpat erat. Quisque erat eros, viverra eget, congue eget, semper rutrum, nulla. Nunc purus.\n\nPhasellus in felis. Donec semper sapien a libero. Nam dui.\n\nProin leo odio, porttitor id, consequat in, consequat ut, nulla. Sed accumsan felis. Ut at dolor quis odio consequat varius.', + creation_date: '11/11/2021', + user_id: 4, +}, { + id: 14, + title: 'Teacher', + description: 'Curabitur at ipsum ac tellus semper interdum. Mauris ullamcorper purus sit amet nulla. Quisque arcu libero, rutrum ac, lobortis vel, dapibus at, diam.', + creation_date: '9/16/2022', + user_id: 18, +}, { + id: 15, + title: 'Programmer IV', + description: 'Integer ac leo. Pellentesque ultrices mattis odio. Donec vitae nisi.\n\nNam ultrices, libero non mattis pulvinar, nulla pede ullamcorper augue, a suscipit nulla elit ac nulla. Sed vel enim sit amet nunc viverra dapibus. Nulla suscipit ligula in lacus.', + creation_date: '9/15/2022', + user_id: 13, +}, { + id: 16, + title: 'Senior Sales Associate', + description: 'Curabitur gravida nisi at nibh. In hac habitasse platea dictumst. Aliquam augue quam, sollicitudin vitae, consectetuer eget, rutrum at, lorem.', + creation_date: '9/15/2022', + user_id: 1, +}, { + id: 17, + title: 'VP Product Management', + description: 'Proin interdum mauris non ligula pellentesque ultrices. Phasellus id sapien in sapien iaculis congue. Vivamus metus arcu, adipiscing molestie, hendrerit at, vulputate vitae, nisl.\n\nAenean lectus. Pellentesque eget nunc. Donec quis orci eget orci vehicula condimentum.', + creation_date: '1/13/2022', + user_id: 10, +}, { + id: 18, + title: 'Occupational Therapist', + description: 'Proin eu mi. Nulla ac enim. In tempor, turpis nec euismod scelerisque, quam turpis adipiscing lorem, vitae mattis nibh ligula nec sem.', + creation_date: '8/30/2022', + user_id: 3, +}, { + id: 19, + title: 'Dental Hygienist', + description: 'Maecenas ut massa quis augue luctus tincidunt. Nulla mollis molestie lorem. Quisque ut erat.\n\nCurabitur gravida nisi at nibh. In hac habitasse platea dictumst. Aliquam augue quam, sollicitudin vitae, consectetuer eget, rutrum at, lorem.', + creation_date: '5/4/2022', + user_id: 10, +}, { + id: 20, + title: 'Computer Systems Analyst IV', + description: 'Cras non velit nec nisi vulputate nonummy. Maecenas tincidunt lacus at velit. Vivamus vel nulla eget eros elementum pellentesque.', + creation_date: '5/14/2022', + user_id: 9, +}]; + +export { + users, reviews, transactions, +}; diff --git a/server/models/index.ts b/server/models/index.ts new file mode 100644 index 0000000..18cddd6 --- /dev/null +++ b/server/models/index.ts @@ -0,0 +1,6 @@ +export { default as Transactions } from './transactions'; +export { default as Reviews } from './reviews'; +export { default as Users } from './users'; + +export { default as Announcements } from './Announcements'; +export { default as Advertisements } from './Advertisements'; diff --git a/server/models/reviews.ts b/server/models/reviews.ts index 88a0671..55ed6c4 100644 --- a/server/models/reviews.ts +++ b/server/models/reviews.ts @@ -22,7 +22,7 @@ interface ReviewsModel is_shown?: boolean - creation_date?: Date + creation_date?: string user_id?: number } @@ -45,10 +45,10 @@ const Reviews = sequelize.define( allowNull: true, }, points: { - type: DataTypes.NUMBER, + type: DataTypes.INTEGER, allowNull: false, validate: { - min: 1, + min: 0, max: 5, }, }, @@ -58,10 +58,10 @@ const Reviews = sequelize.define( }, creation_date: { type: DataTypes.DATE, - defaultValue: new Date(), + defaultValue: Date(), }, user_id: { - type: DataTypes.NUMBER, + type: DataTypes.INTEGER, allowNull: false, }, }, diff --git a/server/models/transactions.ts b/server/models/transactions.ts index e95c0e5..5d57f57 100644 --- a/server/models/transactions.ts +++ b/server/models/transactions.ts @@ -42,10 +42,10 @@ const Transactions = sequelize.define( }, creation_date: { type: DataTypes.DATE, - defaultValue: new Date(), + defaultValue: Date(), }, user_id: { - type: DataTypes.NUMBER, + type: DataTypes.INTEGER, allowNull: false, }, }, diff --git a/server/models/users.ts b/server/models/users.ts index 7a69712..91280f7 100644 --- a/server/models/users.ts +++ b/server/models/users.ts @@ -7,26 +7,23 @@ import { } from 'sequelize'; import sequelize from '../database/config/connection'; -interface UsersModel - extends Model< - InferAttributes, - InferCreationAttributes - > { +export interface UsersModel + extends Model { id: CreationOptional - first_name?: string + first_name: string - last_name?: string + last_name: string - email?: string + email: string - phone_number?: string + phone_number: string - creation_date?: Date + creation_date: string - roles?: 'ADMIN' | 'USER' + roles: 'ADMIN' | 'USER' - hased_password?: string + hased_password: string } const Users = sequelize.define( @@ -60,7 +57,7 @@ const Users = sequelize.define( }, creation_date: { type: DataTypes.DATE, - defaultValue: new Date(), + defaultValue: Date(), }, roles: { type: DataTypes.ENUM('ADMIN', 'USER'), From 6c8b52923987c8d0b7d23002681dc18c8e30fbe8 Mon Sep 17 00:00:00 2001 From: mohjaps Date: Thu, 13 Oct 2022 15:29:48 +0300 Subject: [PATCH 04/12] fake data --- server/app.ts | 19 ++++++++++++++++++- server/models/Review.ts | 9 ++------- server/models/Transaction.ts | 9 ++------- server/models/User.ts | 17 ++++++----------- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/server/app.ts b/server/app.ts index f434177..80e9973 100644 --- a/server/app.ts +++ b/server/app.ts @@ -4,7 +4,9 @@ import dotenv from 'dotenv'; import cookieParser from 'cookie-parser'; import { join } from 'path'; import morgan from 'morgan'; -import { Announcement, Advertisement } from './models'; +import { + Announcement, Advertisement, User, Transaction, Review, +} from './models'; dotenv.config(); @@ -35,6 +37,21 @@ app.get('/advertisements', async (req, res) => { res.json({ message: 'Advertisements', data }); }); +app.get('/Users', async (req, res) => { + const data = await User.findAll(); + res.json({ message: 'Users', data }); +}); + +app.get('/Transactions', async (req, res) => { + const data = await Transaction.findAll(); + res.json({ message: 'Transactions', data }); +}); + +app.get('/Reviews', async (req, res) => { + const data = await Review.findAll(); + res.json({ message: 'Reviews', data }); +}); + if (NODE_ENV === 'production') { app.use(express.static(join(__dirname, '..', 'client', 'build'))); app.get('*', (req, res) => { diff --git a/server/models/Review.ts b/server/models/Review.ts index 51100f1..fe9b73a 100644 --- a/server/models/Review.ts +++ b/server/models/Review.ts @@ -7,13 +7,12 @@ const Review = sequelize.define( 'Reviews', { id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, + type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true, }, title: { - type: DataTypes.STRING(255), + type: DataTypes.STRING, allowNull: false, }, description: { @@ -32,10 +31,6 @@ const Review = sequelize.define( type: DataTypes.BOOLEAN, allowNull: false, }, - creation_date: { - type: DataTypes.DATE, - defaultValue: Date(), - }, user_id: { type: DataTypes.INTEGER, allowNull: false, diff --git a/server/models/Transaction.ts b/server/models/Transaction.ts index 8327e4e..102c03b 100644 --- a/server/models/Transaction.ts +++ b/server/models/Transaction.ts @@ -7,23 +7,18 @@ const Transaction = sequelize.define( 'Transactions', { id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, + type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true, }, title: { - type: DataTypes.STRING(255), + type: DataTypes.STRING, allowNull: false, }, description: { type: DataTypes.TEXT, allowNull: true, }, - creation_date: { - type: DataTypes.DATE, - defaultValue: Date(), - }, user_id: { type: DataTypes.INTEGER, allowNull: false, diff --git a/server/models/User.ts b/server/models/User.ts index 8c85e2c..718e2b3 100644 --- a/server/models/User.ts +++ b/server/models/User.ts @@ -7,41 +7,36 @@ const User = sequelize.define( 'Transactions', { id: { - type: DataTypes.UUID, - defaultValue: DataTypes.UUIDV4, + type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true, }, first_name: { - type: DataTypes.STRING(100), + type: DataTypes.STRING, allowNull: false, }, last_name: { - type: DataTypes.STRING(100), + type: DataTypes.STRING, allowNull: false, }, email: { - type: DataTypes.STRING(100), + type: DataTypes.STRING, allowNull: true, validate: { isEmail: true, }, }, phone_number: { - type: DataTypes.STRING(14), + type: DataTypes.STRING, unique: true, allowNull: false, }, - creation_date: { - type: DataTypes.DATE, - defaultValue: Date(), - }, roles: { type: DataTypes.ENUM('ADMIN', 'USER'), allowNull: false, }, hased_password: { - type: DataTypes.STRING(64), + type: DataTypes.STRING, validate: { is: /^[0-9a-f]{64}$/i, }, From 9f25f6b2077cdc7a07563d1607e8eaf19b6e92b8 Mon Sep 17 00:00:00 2001 From: mohjaps Date: Fri, 14 Oct 2022 19:08:02 +0300 Subject: [PATCH 05/12] Solve Tables's Name Problem --- server/database/config/fakeData.ts | 166 ++--------------------------- server/models/Transaction.ts | 2 +- 2 files changed, 9 insertions(+), 159 deletions(-) diff --git a/server/database/config/fakeData.ts b/server/database/config/fakeData.ts index f08b517..4e0df76 100644 --- a/server/database/config/fakeData.ts +++ b/server/database/config/fakeData.ts @@ -4,7 +4,6 @@ const Users = [{ last_name: 'Cotte', email: 'jcotte0@people.com.cn', phone_number: '318-530-6030', - creation_date: '12/2/2021', roles: 'ADMIN', hased_password: 'eDuvQFk2tKR', }, { @@ -13,7 +12,6 @@ const Users = [{ last_name: 'Belt', email: 'gbelt1@thetimes.co.uk', phone_number: '235-783-1177', - creation_date: '2/16/2022', roles: 'USER', hased_password: 'j1Lwy1VL3k', }, { @@ -22,7 +20,6 @@ const Users = [{ last_name: 'Lobe', email: 'tlobe2@angelfire.com', phone_number: '498-722-9258', - creation_date: '4/8/2022', roles: 'USER', hased_password: 'UuXPw5W7H', }, { @@ -31,7 +28,6 @@ const Users = [{ last_name: 'Gravey', email: 'mgravey3@slideshare.net', phone_number: '172-408-5906', - creation_date: '1/8/2022', roles: 'USER', hased_password: '3ZzMhbjfY6', }, { @@ -40,7 +36,6 @@ const Users = [{ last_name: 'Scogin', email: 'cscogin4@nytimes.com', phone_number: '910-220-7086', - creation_date: '6/29/2022', roles: 'USER', hased_password: '1edtRkJrJz1', }, { @@ -49,7 +44,6 @@ const Users = [{ last_name: 'Frail', email: 'bfrail5@google.com.br', phone_number: '178-978-2984', - creation_date: '11/29/2021', roles: 'USER', hased_password: 'FBL5ZQ8', }, { @@ -58,7 +52,6 @@ const Users = [{ last_name: 'Justis', email: 'bjustis6@state.gov', phone_number: '153-758-3576', - creation_date: '9/29/2022', roles: 'USER', hased_password: 'rqynGoZr6XJ1', }, { @@ -67,7 +60,6 @@ const Users = [{ last_name: 'Saltsberg', email: 'esaltsberg7@naver.com', phone_number: '746-342-8706', - creation_date: '1/17/2022', roles: 'USER', hased_password: 'NOj9CbSR', }, { @@ -76,7 +68,6 @@ const Users = [{ last_name: 'McGairl', email: 'cmcgairl8@livejournal.com', phone_number: '839-484-5210', - creation_date: '3/21/2022', roles: 'USER', hased_password: 'a82tTF', }, { @@ -85,7 +76,6 @@ const Users = [{ last_name: 'Shannahan', email: 'cshannahan9@wunderground.com', phone_number: '916-108-1812', - creation_date: '7/16/2022', roles: 'USER', hased_password: 'VWqe6ZR', }, { @@ -94,7 +84,6 @@ const Users = [{ last_name: 'Nadin', email: 'enadina@php.net', phone_number: '900-620-7479', - creation_date: '3/27/2022', roles: 'USER', hased_password: 'CfBoa3bYZkPr', }, { @@ -103,7 +92,6 @@ const Users = [{ last_name: 'Bront', email: 'mbrontb@phpbb.com', phone_number: '959-720-9384', - creation_date: '9/3/2022', roles: 'USER', hased_password: 'bVVXcX3nLF', }, { @@ -112,7 +100,6 @@ const Users = [{ last_name: 'Scoggans', email: 'sscoggansc@noaa.gov', phone_number: '521-649-4149', - creation_date: '3/22/2022', roles: 'USER', hased_password: 'D5PQW7u7jv3', }, { @@ -121,7 +108,6 @@ const Users = [{ last_name: 'Johnigan', email: 'ejohnigand@blinklist.com', phone_number: '148-222-5388', - creation_date: '1/11/2022', roles: 'USER', hased_password: 'bVDwvHM', }, { @@ -130,7 +116,6 @@ const Users = [{ last_name: 'Binks', email: 'abinkse@flickr.com', phone_number: '907-611-5915', - creation_date: '11/26/2021', roles: 'USER', hased_password: 'OT3k2suBFF9X', }, { @@ -139,7 +124,6 @@ const Users = [{ last_name: 'Bridge', email: 'lbridgef@columbia.edu', phone_number: '813-752-6434', - creation_date: '11/4/2021', roles: 'USER', hased_password: 'L1g4CHQWq5', }, { @@ -148,7 +132,6 @@ const Users = [{ last_name: 'Jayme', email: 'ajaymeg@nifty.com', phone_number: '588-244-3150', - creation_date: '4/28/2022', roles: 'USER', hased_password: 'ojldRgoVO', }, { @@ -157,7 +140,6 @@ const Users = [{ last_name: 'Ivanyushkin', email: 'bivanyushkinh@behance.net', phone_number: '390-816-5923', - creation_date: '7/2/2022', roles: 'USER', hased_password: 'zBZRkc7qlYA', }, { @@ -166,7 +148,6 @@ const Users = [{ last_name: 'Stranio', email: 'jstranioi@ibm.com', phone_number: '405-527-5827', - creation_date: '6/27/2022', roles: 'USER', hased_password: 'kvd7ziyp', }, { @@ -175,7 +156,6 @@ const Users = [{ last_name: 'Allridge', email: 'gallridgej@latimes.com', phone_number: '330-739-1479', - creation_date: '1/6/2022', roles: 'USER', hased_password: 'zgGeNhGc', }]; @@ -186,7 +166,6 @@ const Reviews = [{ description: 'Nullam porttitor lacus at turpis. Donec posuere metus vitae ipsum. Aliquam non mauris.\n\nMorbi non lectus. Aliquam sit amet diam in magna bibendum imperdiet. Nullam orci pede, venenatis non, sodales sed, tincidunt eu, felis.\n\nFusce posuere felis sed lacus. Morbi sem mauris, laoreet ut, rhoncus aliquet, pulvinar sed, nisl. Nunc rhoncus dui vel sem.', points: 2, is_shown: false, - creation_date: '9/13/2022', user_id: 15, }, { id: 2, @@ -194,7 +173,6 @@ const Reviews = [{ description: 'Aliquam quis turpis eget elit sodales scelerisque. Mauris sit amet eros. Suspendisse accumsan tortor quis turpis.', points: 2, is_shown: false, - creation_date: '5/20/2022', user_id: 14, }, { id: 3, @@ -202,7 +180,6 @@ const Reviews = [{ description: 'Vestibulum ac est lacinia nisi venenatis tristique. Fusce congue, diam id ornare imperdiet, sapien urna pretium nisl, ut volutpat sapien arcu sed augue. Aliquam erat volutpat.\n\nIn congue. Etiam justo. Etiam pretium iaculis justo.\n\nIn hac habitasse platea dictumst. Etiam faucibus cursus urna. Ut tellus.', points: 0, is_shown: false, - creation_date: '3/25/2022', user_id: 1, }, { id: 4, @@ -210,7 +187,6 @@ const Reviews = [{ description: 'Integer tincidunt ante vel ipsum. Praesent blandit lacinia erat. Vestibulum sed magna at nunc commodo placerat.\n\nPraesent blandit. Nam nulla. Integer pede justo, lacinia eget, tincidunt eget, tempus vel, pede.\n\nMorbi porttitor lorem id ligula. Suspendisse ornare consequat lectus. In est risus, auctor sed, tristique in, tempus sit amet, sem.', points: 2, is_shown: false, - creation_date: '2/10/2022', user_id: 20, }, { id: 5, @@ -218,7 +194,6 @@ const Reviews = [{ description: 'Cras mi pede, malesuada in, imperdiet et, commodo vulputate, justo. In blandit ultrices enim. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\n\nProin interdum mauris non ligula pellentesque ultrices. Phasellus id sapien in sapien iaculis congue. Vivamus metus arcu, adipiscing molestie, hendrerit at, vulputate vitae, nisl.', points: 0, is_shown: true, - creation_date: '12/13/2021', user_id: 14, }, { id: 6, @@ -226,7 +201,6 @@ const Reviews = [{ description: 'In quis justo. Maecenas rhoncus aliquam lacus. Morbi quis tortor id nulla ultrices aliquet.\n\nMaecenas leo odio, condimentum id, luctus nec, molestie sed, justo. Pellentesque viverra pede ac diam. Cras pellentesque volutpat dui.', points: 4, is_shown: true, - creation_date: '11/1/2021', user_id: 20, }, { id: 7, @@ -234,7 +208,6 @@ const Reviews = [{ description: 'Cras non velit nec nisi vulputate nonummy. Maecenas tincidunt lacus at velit. Vivamus vel nulla eget eros elementum pellentesque.', points: 2, is_shown: false, - creation_date: '12/20/2021', user_id: 10, }, { id: 8, @@ -242,7 +215,6 @@ const Reviews = [{ description: 'Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.\n\nPhasellus sit amet erat. Nulla tempus. Vivamus in felis eu sapien cursus vestibulum.\n\nProin eu mi. Nulla ac enim. In tempor, turpis nec euismod scelerisque, quam turpis adipiscing lorem, vitae mattis nibh ligula nec sem.', points: 3, is_shown: true, - creation_date: '8/12/2022', user_id: 3, }, { id: 9, @@ -250,7 +222,6 @@ const Reviews = [{ description: 'Nullam porttitor lacus at turpis. Donec posuere metus vitae ipsum. Aliquam non mauris.', points: 2, is_shown: true, - creation_date: '2/12/2022', user_id: 15, }, { id: 10, @@ -258,7 +229,6 @@ const Reviews = [{ description: 'Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vivamus vestibulum sagittis sapien. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.\n\nEtiam vel augue. Vestibulum rutrum rutrum neque. Aenean auctor gravida sem.', points: 0, is_shown: true, - creation_date: '6/23/2022', user_id: 17, }, { id: 11, @@ -266,7 +236,6 @@ const Reviews = [{ description: 'Duis bibendum, felis sed interdum venenatis, turpis enim blandit mi, in porttitor pede justo eu massa. Donec dapibus. Duis at velit eu est congue elementum.', points: 4, is_shown: false, - creation_date: '6/19/2022', user_id: 3, }, { id: 12, @@ -274,7 +243,6 @@ const Reviews = [{ description: 'Maecenas tristique, est et tempus semper, est quam pharetra magna, ac consequat metus sapien ut nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris viverra diam vitae quam. Suspendisse potenti.\n\nNullam porttitor lacus at turpis. Donec posuere metus vitae ipsum. Aliquam non mauris.\n\nMorbi non lectus. Aliquam sit amet diam in magna bibendum imperdiet. Nullam orci pede, venenatis non, sodales sed, tincidunt eu, felis.', points: 1, is_shown: true, - creation_date: '2/9/2022', user_id: 12, }, { id: 13, @@ -282,7 +250,6 @@ const Reviews = [{ description: 'Mauris enim leo, rhoncus sed, vestibulum sit amet, cursus id, turpis. Integer aliquet, massa id lobortis convallis, tortor risus dapibus augue, vel accumsan tellus nisi eu orci. Mauris lacinia sapien quis libero.', points: 3, is_shown: false, - creation_date: '10/12/2022', user_id: 8, }, { id: 14, @@ -290,7 +257,6 @@ const Reviews = [{ description: 'Sed sagittis. Nam congue, risus semper porta volutpat, quam pede lobortis ligula, sit amet eleifend pede libero quis orci. Nullam molestie nibh in lectus.\n\nPellentesque at nulla. Suspendisse potenti. Cras in purus eu magna vulputate luctus.', points: 5, is_shown: false, - creation_date: '8/21/2022', user_id: 16, }, { id: 15, @@ -298,7 +264,6 @@ const Reviews = [{ description: 'Maecenas ut massa quis augue luctus tincidunt. Nulla mollis molestie lorem. Quisque ut erat.', points: 5, is_shown: false, - creation_date: '8/25/2022', user_id: 7, }, { id: 16, @@ -306,7 +271,6 @@ const Reviews = [{ description: 'Aenean lectus. Pellentesque eget nunc. Donec quis orci eget orci vehicula condimentum.\n\nCurabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.', points: 2, is_shown: false, - creation_date: '10/29/2021', user_id: 18, }, { id: 17, @@ -314,7 +278,6 @@ const Reviews = [{ description: 'Integer ac leo. Pellentesque ultrices mattis odio. Donec vitae nisi.', points: 1, is_shown: true, - creation_date: '10/5/2022', user_id: 13, }, { id: 18, @@ -322,7 +285,6 @@ const Reviews = [{ description: 'Fusce consequat. Nulla nisl. Nunc nisl.\n\nDuis bibendum, felis sed interdum venenatis, turpis enim blandit mi, in porttitor pede justo eu massa. Donec dapibus. Duis at velit eu est congue elementum.', points: 2, is_shown: false, - creation_date: '7/7/2022', user_id: 13, }, { id: 19, @@ -330,7 +292,6 @@ const Reviews = [{ description: 'Maecenas tristique, est et tempus semper, est quam pharetra magna, ac consequat metus sapien ut nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris viverra diam vitae quam. Suspendisse potenti.', points: 0, is_shown: true, - creation_date: '3/3/2022', user_id: 8, }, { id: 20, @@ -338,131 +299,20 @@ const Reviews = [{ description: 'Nam ultrices, libero non mattis pulvinar, nulla pede ullamcorper augue, a suscipit nulla elit ac nulla. Sed vel enim sit amet nunc viverra dapibus. Nulla suscipit ligula in lacus.', points: 3, is_shown: true, - creation_date: '10/30/2021', user_id: 4, }]; const Transactions = [{ - id: 1, - title: 'Developer I', - description: 'Maecenas leo odio, condimentum id, luctus nec, molestie sed, justo. Pellentesque viverra pede ac diam. Cras pellentesque volutpat dui.\n\nMaecenas tristique, est et tempus semper, est quam pharetra magna, ac consequat metus sapien ut nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris viverra diam vitae quam. Suspendisse potenti.', - creation_date: '4/8/2022', + title: 'DeveloperI', + description: 'Maecenas leo odio, condimentum id, luctus nec, molestie sed, justo. Pellentesque viverra pede ac diam. Cras pellentesque volutpat dui.Maecenas tristique, est et tempus semper, est quam pharetra magna, ac consequat metus sapien ut nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris viverra diam vitae quam. Suspendisse potenti.', user_id: 8, -}, { - id: 2, - title: 'Senior Editor', - description: 'Aenean lectus. Pellentesque eget nunc. Donec quis orci eget orci vehicula condimentum.\n\nCurabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.', - creation_date: '1/11/2022', - user_id: 9, -}, { - id: 3, - title: 'Graphic Designer', - description: 'Duis bibendum, felis sed interdum venenatis, turpis enim blandit mi, in porttitor pede justo eu massa. Donec dapibus. Duis at velit eu est congue elementum.\n\nIn hac habitasse platea dictumst. Morbi vestibulum, velit id pretium iaculis, diam erat fermentum justo, nec condimentum neque sapien placerat ante. Nulla justo.\n\nAliquam quis turpis eget elit sodales scelerisque. Mauris sit amet eros. Suspendisse accumsan tortor quis turpis.', - creation_date: '2/4/2022', - user_id: 20, -}, { - id: 4, - title: 'Analog Circuit Design manager', - description: 'Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.\n\nPhasellus sit amet erat. Nulla tempus. Vivamus in felis eu sapien cursus vestibulum.\n\nProin eu mi. Nulla ac enim. In tempor, turpis nec euismod scelerisque, quam turpis adipiscing lorem, vitae mattis nibh ligula nec sem.', - creation_date: '4/17/2022', - user_id: 17, -}, { - id: 5, - title: 'Librarian', - description: 'Nullam porttitor lacus at turpis. Donec posuere metus vitae ipsum. Aliquam non mauris.\n\nMorbi non lectus. Aliquam sit amet diam in magna bibendum imperdiet. Nullam orci pede, venenatis non, sodales sed, tincidunt eu, felis.\n\nFusce posuere felis sed lacus. Morbi sem mauris, laoreet ut, rhoncus aliquet, pulvinar sed, nisl. Nunc rhoncus dui vel sem.', - creation_date: '11/1/2021', - user_id: 4, -}, { - id: 6, - title: 'Librarian', - description: 'Aliquam quis turpis eget elit sodales scelerisque. Mauris sit amet eros. Suspendisse accumsan tortor quis turpis.\n\nSed ante. Vivamus tortor. Duis mattis egestas metus.', - creation_date: '9/1/2022', - user_id: 13, -}, { - id: 7, - title: 'Actuary', - description: 'Duis bibendum. Morbi non quam nec dui luctus rutrum. Nulla tellus.\n\nIn sagittis dui vel nisl. Duis ac nibh. Fusce lacus purus, aliquet at, feugiat non, pretium quis, lectus.', - creation_date: '7/5/2022', - user_id: 16, -}, { - id: 8, - title: 'Accountant III', - description: 'Suspendisse potenti. In eleifend quam a odio. In hac habitasse platea dictumst.\n\nMaecenas ut massa quis augue luctus tincidunt. Nulla mollis molestie lorem. Quisque ut erat.', - creation_date: '4/24/2022', - user_id: 6, -}, { - id: 9, - title: 'Cost Accountant', - description: 'Proin interdum mauris non ligula pellentesque ultrices. Phasellus id sapien in sapien iaculis congue. Vivamus metus arcu, adipiscing molestie, hendrerit at, vulputate vitae, nisl.', - creation_date: '7/7/2022', - user_id: 6, -}, { - id: 10, - title: 'Senior Financial Analyst', - description: 'Duis bibendum. Morbi non quam nec dui luctus rutrum. Nulla tellus.', - creation_date: '1/16/2022', - user_id: 11, -}, { - id: 11, - title: 'Research Assistant I', - description: 'Morbi porttitor lorem id ligula. Suspendisse ornare consequat lectus. In est risus, auctor sed, tristique in, tempus sit amet, sem.\n\nFusce consequat. Nulla nisl. Nunc nisl.\n\nDuis bibendum, felis sed interdum venenatis, turpis enim blandit mi, in porttitor pede justo eu massa. Donec dapibus. Duis at velit eu est congue elementum.', - creation_date: '8/13/2022', - user_id: 17, -}, { - id: 12, - title: 'Internal Auditor', - description: 'Integer ac leo. Pellentesque ultrices mattis odio. Donec vitae nisi.\n\nNam ultrices, libero non mattis pulvinar, nulla pede ullamcorper augue, a suscipit nulla elit ac nulla. Sed vel enim sit amet nunc viverra dapibus. Nulla suscipit ligula in lacus.', - creation_date: '3/6/2022', - user_id: 12, -}, { - id: 13, - title: 'Internal Auditor', - description: 'Quisque porta volutpat erat. Quisque erat eros, viverra eget, congue eget, semper rutrum, nulla. Nunc purus.\n\nPhasellus in felis. Donec semper sapien a libero. Nam dui.\n\nProin leo odio, porttitor id, consequat in, consequat ut, nulla. Sed accumsan felis. Ut at dolor quis odio consequat varius.', - creation_date: '11/11/2021', - user_id: 4, -}, { - id: 14, - title: 'Teacher', - description: 'Curabitur at ipsum ac tellus semper interdum. Mauris ullamcorper purus sit amet nulla. Quisque arcu libero, rutrum ac, lobortis vel, dapibus at, diam.', - creation_date: '9/16/2022', - user_id: 18, -}, { - id: 15, - title: 'Programmer IV', - description: 'Integer ac leo. Pellentesque ultrices mattis odio. Donec vitae nisi.\n\nNam ultrices, libero non mattis pulvinar, nulla pede ullamcorper augue, a suscipit nulla elit ac nulla. Sed vel enim sit amet nunc viverra dapibus. Nulla suscipit ligula in lacus.', - creation_date: '9/15/2022', - user_id: 13, -}, { - id: 16, - title: 'Senior Sales Associate', - description: 'Curabitur gravida nisi at nibh. In hac habitasse platea dictumst. Aliquam augue quam, sollicitudin vitae, consectetuer eget, rutrum at, lorem.', - creation_date: '9/15/2022', - user_id: 1, -}, { - id: 17, - title: 'VP Product Management', - description: 'Proin interdum mauris non ligula pellentesque ultrices. Phasellus id sapien in sapien iaculis congue. Vivamus metus arcu, adipiscing molestie, hendrerit at, vulputate vitae, nisl.\n\nAenean lectus. Pellentesque eget nunc. Donec quis orci eget orci vehicula condimentum.', - creation_date: '1/13/2022', - user_id: 10, -}, { - id: 18, - title: 'Occupational Therapist', - description: 'Proin eu mi. Nulla ac enim. In tempor, turpis nec euismod scelerisque, quam turpis adipiscing lorem, vitae mattis nibh ligula nec sem.', - creation_date: '8/30/2022', - user_id: 3, -}, { - id: 19, - title: 'Dental Hygienist', - description: 'Maecenas ut massa quis augue luctus tincidunt. Nulla mollis molestie lorem. Quisque ut erat.\n\nCurabitur gravida nisi at nibh. In hac habitasse platea dictumst. Aliquam augue quam, sollicitudin vitae, consectetuer eget, rutrum at, lorem.', - creation_date: '5/4/2022', - user_id: 10, -}, { - id: 20, - title: 'Computer Systems Analyst IV', - description: 'Cras non velit nec nisi vulputate nonummy. Maecenas tincidunt lacus at velit. Vivamus vel nulla eget eros elementum pellentesque.', - creation_date: '5/14/2022', +}, +{ + title: 'SeniorEditor', + description: 'Aenean lectus. Pellentesque eget nunc. Donec quis orci eget orci vehicula condimentum.Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.', user_id: 9, -}]; +}, +]; const Announcements = [ { diff --git a/server/models/Transaction.ts b/server/models/Transaction.ts index 102c03b..3a03a95 100644 --- a/server/models/Transaction.ts +++ b/server/models/Transaction.ts @@ -4,7 +4,7 @@ import { import sequelize from '../database/config/connection'; const Transaction = sequelize.define( - 'Transactions', + 'Processes', { id: { type: DataTypes.INTEGER, From b4426dca290df0f178b67c2a635264fbbf238174 Mon Sep 17 00:00:00 2001 From: mohjaps Date: Fri, 14 Oct 2022 19:08:50 +0300 Subject: [PATCH 06/12] Set Relationships --- server/database/config/build.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server/database/config/build.ts b/server/database/config/build.ts index b3c25d0..4779efa 100644 --- a/server/database/config/build.ts +++ b/server/database/config/build.ts @@ -14,10 +14,18 @@ const insertDB = async () => { await sequelize.sync({ force: true }); await Announcement.bulkCreate(Announcements); await Advertisement.bulkCreate(Advertisements); - await Review.bulkCreate(Reviews); await User.bulkCreate(Users); + await Review.bulkCreate(Reviews); await Transaction.bulkCreate(Transactions); + // Relaships + Transaction.hasOne(User, { + foreignKey: 'user_id', + }); + Review.hasOne(User, { + foreignKey: 'user_id', + }); + // eslint-disable-next-line no-console console.log('Build Database Successfully'); } catch (err) { From 30bf4945cdc7291d3a252cc5a1ef7a4043fa444a Mon Sep 17 00:00:00 2001 From: mohjaps Date: Sun, 16 Oct 2022 09:48:54 +0300 Subject: [PATCH 07/12] Shift Rel into index --- server/app.ts | 8 +- server/database/config/build.ts | 16 +- server/database/config/fakeData.ts | 428 +++++-------------- server/models/{Transaction.ts => Payment.ts} | 6 +- server/models/index.ts | 23 +- 5 files changed, 135 insertions(+), 346 deletions(-) rename server/models/{Transaction.ts => Payment.ts} (84%) diff --git a/server/app.ts b/server/app.ts index 80e9973..bef9e79 100644 --- a/server/app.ts +++ b/server/app.ts @@ -5,7 +5,7 @@ import cookieParser from 'cookie-parser'; import { join } from 'path'; import morgan from 'morgan'; import { - Announcement, Advertisement, User, Transaction, Review, + Announcement, Advertisement, User, Payment, Review, } from './models'; dotenv.config(); @@ -42,9 +42,9 @@ app.get('/Users', async (req, res) => { res.json({ message: 'Users', data }); }); -app.get('/Transactions', async (req, res) => { - const data = await Transaction.findAll(); - res.json({ message: 'Transactions', data }); +app.get('/Payments', async (req, res) => { + const data = await Payment.findAll(); + res.json({ message: 'Payments', data }); }); app.get('/Reviews', async (req, res) => { diff --git a/server/database/config/build.ts b/server/database/config/build.ts index 4779efa..7c88cdc 100644 --- a/server/database/config/build.ts +++ b/server/database/config/build.ts @@ -1,13 +1,13 @@ import sequelize from './connection'; import { - Announcements, Advertisements, Users, Reviews, Transactions, + Announcements, Advertisements, Users, Reviews, Payments, } from './fakeData'; import { - Announcement, Advertisement, Review, User, Transaction, -} from '../../models/index'; + Announcement, Advertisement, Review, User, Payment, +} from '../../models'; const insertDB = async () => { try { @@ -16,15 +16,7 @@ const insertDB = async () => { await Advertisement.bulkCreate(Advertisements); await User.bulkCreate(Users); await Review.bulkCreate(Reviews); - await Transaction.bulkCreate(Transactions); - - // Relaships - Transaction.hasOne(User, { - foreignKey: 'user_id', - }); - Review.hasOne(User, { - foreignKey: 'user_id', - }); + await Payment.bulkCreate(Payments); // eslint-disable-next-line no-console console.log('Build Database Successfully'); diff --git a/server/database/config/fakeData.ts b/server/database/config/fakeData.ts index 4e0df76..d0fca96 100644 --- a/server/database/config/fakeData.ts +++ b/server/database/config/fakeData.ts @@ -1,332 +1,112 @@ -const Users = [{ - id: 1, - first_name: 'Jules', - last_name: 'Cotte', - email: 'jcotte0@people.com.cn', - phone_number: '318-530-6030', - roles: 'ADMIN', - hased_password: 'eDuvQFk2tKR', -}, { - id: 2, - first_name: 'Gwen', - last_name: 'Belt', - email: 'gbelt1@thetimes.co.uk', - phone_number: '235-783-1177', - roles: 'USER', - hased_password: 'j1Lwy1VL3k', -}, { - id: 3, - first_name: 'Trumann', - last_name: 'Lobe', - email: 'tlobe2@angelfire.com', - phone_number: '498-722-9258', - roles: 'USER', - hased_password: 'UuXPw5W7H', -}, { - id: 4, - first_name: 'Meta', - last_name: 'Gravey', - email: 'mgravey3@slideshare.net', - phone_number: '172-408-5906', - roles: 'USER', - hased_password: '3ZzMhbjfY6', -}, { - id: 5, - first_name: 'Chryste', - last_name: 'Scogin', - email: 'cscogin4@nytimes.com', - phone_number: '910-220-7086', - roles: 'USER', - hased_password: '1edtRkJrJz1', -}, { - id: 6, - first_name: 'Bettye', - last_name: 'Frail', - email: 'bfrail5@google.com.br', - phone_number: '178-978-2984', - roles: 'USER', - hased_password: 'FBL5ZQ8', -}, { - id: 7, - first_name: 'Barbi', - last_name: 'Justis', - email: 'bjustis6@state.gov', - phone_number: '153-758-3576', - roles: 'USER', - hased_password: 'rqynGoZr6XJ1', -}, { - id: 8, - first_name: 'Ebba', - last_name: 'Saltsberg', - email: 'esaltsberg7@naver.com', - phone_number: '746-342-8706', - roles: 'USER', - hased_password: 'NOj9CbSR', -}, { - id: 9, - first_name: 'Cinnamon', - last_name: 'McGairl', - email: 'cmcgairl8@livejournal.com', - phone_number: '839-484-5210', - roles: 'USER', - hased_password: 'a82tTF', -}, { - id: 10, - first_name: 'Cordell', - last_name: 'Shannahan', - email: 'cshannahan9@wunderground.com', - phone_number: '916-108-1812', - roles: 'USER', - hased_password: 'VWqe6ZR', -}, { - id: 11, - first_name: 'Elisha', - last_name: 'Nadin', - email: 'enadina@php.net', - phone_number: '900-620-7479', - roles: 'USER', - hased_password: 'CfBoa3bYZkPr', -}, { - id: 12, - first_name: 'Maxi', - last_name: 'Bront', - email: 'mbrontb@phpbb.com', - phone_number: '959-720-9384', - roles: 'USER', - hased_password: 'bVVXcX3nLF', -}, { - id: 13, - first_name: 'Star', - last_name: 'Scoggans', - email: 'sscoggansc@noaa.gov', - phone_number: '521-649-4149', - roles: 'USER', - hased_password: 'D5PQW7u7jv3', -}, { - id: 14, - first_name: 'Eben', - last_name: 'Johnigan', - email: 'ejohnigand@blinklist.com', - phone_number: '148-222-5388', - roles: 'USER', - hased_password: 'bVDwvHM', -}, { - id: 15, - first_name: 'Aimil', - last_name: 'Binks', - email: 'abinkse@flickr.com', - phone_number: '907-611-5915', - roles: 'USER', - hased_password: 'OT3k2suBFF9X', -}, { - id: 16, - first_name: 'Lyn', - last_name: 'Bridge', - email: 'lbridgef@columbia.edu', - phone_number: '813-752-6434', - roles: 'USER', - hased_password: 'L1g4CHQWq5', -}, { - id: 17, - first_name: 'Ana', - last_name: 'Jayme', - email: 'ajaymeg@nifty.com', - phone_number: '588-244-3150', - roles: 'USER', - hased_password: 'ojldRgoVO', -}, { - id: 18, - first_name: 'Barnard', - last_name: 'Ivanyushkin', - email: 'bivanyushkinh@behance.net', - phone_number: '390-816-5923', - roles: 'USER', - hased_password: 'zBZRkc7qlYA', -}, { - id: 19, - first_name: 'Jeanelle', - last_name: 'Stranio', - email: 'jstranioi@ibm.com', - phone_number: '405-527-5827', - roles: 'USER', - hased_password: 'kvd7ziyp', -}, { - id: 20, - first_name: 'Gwenneth', - last_name: 'Allridge', - email: 'gallridgej@latimes.com', - phone_number: '330-739-1479', - roles: 'USER', - hased_password: 'zgGeNhGc', -}]; +const Users = [ + { + id: 1, + first_name: 'أحمد', + last_name: 'سعيد', + email: 'jcotte0@people.com.cn', + phone_number: '0591000100', + roles: 'ADMIN', + hased_password: '$2y$10$MKpnqAAinu5wjl/MYRc3U.XApWTaEexvI4DMaJA.XZTou5lvpSPfu', + }, + { + id: 2, + first_name: 'خالد', + last_name: 'عمر', + email: 'gbelt1@thetimes.co.uk', + phone_number: '235-783-1177', + roles: 'USER', + hased_password: '$2y$10$ROMcXqVNwbepoV6ZdTsTa.6/iego9a72vzSK70pF/S8Oxe/y8tLeO', + }, + { + id: 3, + first_name: 'سمير', + last_name: 'عبد الله', + email: 'tlobe2@angelfire.com', + phone_number: '498-722-9258', + roles: 'USER', + hased_password: '$2y$10$NrRa5y454oIukcfU/iNDruP2iEJPm9UGlHqyhZiyd5mY1fy2vULkG', + }, + { + id: 4, + first_name: 'مهند', + last_name: 'محمد', + email: 'mgravey3@slideshare.net', + phone_number: '172-408-5906', + roles: 'USER', + hased_password: '$2y$10$dOSPYdqciJCM9U10HiWtCOg9j6jpMD69rMPV/2LI/dDL4SxLATkNG', + }, + { + id: 5, + first_name: 'تميم', + last_name: 'سليم', + email: 'cscogin4@nytimes.com', + phone_number: '910-220-7086', + roles: 'USER', + hased_password: '$2y$10$6Y1AcLQDLM7vSSu1A5dj9e61YgCFACEXoBP3NxJ4qX/1SeUUXLFtm', + }, +]; -const Reviews = [{ - id: 1, - title: 'Financial Advisor', - description: 'Nullam porttitor lacus at turpis. Donec posuere metus vitae ipsum. Aliquam non mauris.\n\nMorbi non lectus. Aliquam sit amet diam in magna bibendum imperdiet. Nullam orci pede, venenatis non, sodales sed, tincidunt eu, felis.\n\nFusce posuere felis sed lacus. Morbi sem mauris, laoreet ut, rhoncus aliquet, pulvinar sed, nisl. Nunc rhoncus dui vel sem.', - points: 2, - is_shown: false, - user_id: 15, -}, { - id: 2, - title: 'Project Manager', - description: 'Aliquam quis turpis eget elit sodales scelerisque. Mauris sit amet eros. Suspendisse accumsan tortor quis turpis.', - points: 2, - is_shown: false, - user_id: 14, -}, { - id: 3, - title: 'Software Engineer I', - description: 'Vestibulum ac est lacinia nisi venenatis tristique. Fusce congue, diam id ornare imperdiet, sapien urna pretium nisl, ut volutpat sapien arcu sed augue. Aliquam erat volutpat.\n\nIn congue. Etiam justo. Etiam pretium iaculis justo.\n\nIn hac habitasse platea dictumst. Etiam faucibus cursus urna. Ut tellus.', - points: 0, - is_shown: false, - user_id: 1, -}, { - id: 4, - title: 'VP Product Management', - description: 'Integer tincidunt ante vel ipsum. Praesent blandit lacinia erat. Vestibulum sed magna at nunc commodo placerat.\n\nPraesent blandit. Nam nulla. Integer pede justo, lacinia eget, tincidunt eget, tempus vel, pede.\n\nMorbi porttitor lorem id ligula. Suspendisse ornare consequat lectus. In est risus, auctor sed, tristique in, tempus sit amet, sem.', - points: 2, - is_shown: false, - user_id: 20, -}, { - id: 5, - title: 'Web Designer IV', - description: 'Cras mi pede, malesuada in, imperdiet et, commodo vulputate, justo. In blandit ultrices enim. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\n\nProin interdum mauris non ligula pellentesque ultrices. Phasellus id sapien in sapien iaculis congue. Vivamus metus arcu, adipiscing molestie, hendrerit at, vulputate vitae, nisl.', - points: 0, - is_shown: true, - user_id: 14, -}, { - id: 6, - title: 'Assistant Media Planner', - description: 'In quis justo. Maecenas rhoncus aliquam lacus. Morbi quis tortor id nulla ultrices aliquet.\n\nMaecenas leo odio, condimentum id, luctus nec, molestie sed, justo. Pellentesque viverra pede ac diam. Cras pellentesque volutpat dui.', - points: 4, - is_shown: true, - user_id: 20, -}, { - id: 7, - title: 'Occupational Therapist', - description: 'Cras non velit nec nisi vulputate nonummy. Maecenas tincidunt lacus at velit. Vivamus vel nulla eget eros elementum pellentesque.', - points: 2, - is_shown: false, - user_id: 10, -}, { - id: 8, - title: 'Data Coordiator', - description: 'Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.\n\nPhasellus sit amet erat. Nulla tempus. Vivamus in felis eu sapien cursus vestibulum.\n\nProin eu mi. Nulla ac enim. In tempor, turpis nec euismod scelerisque, quam turpis adipiscing lorem, vitae mattis nibh ligula nec sem.', - points: 3, - is_shown: true, - user_id: 3, -}, { - id: 9, - title: 'Geologist I', - description: 'Nullam porttitor lacus at turpis. Donec posuere metus vitae ipsum. Aliquam non mauris.', - points: 2, - is_shown: true, - user_id: 15, -}, { - id: 10, - title: 'Web Developer I', - description: 'Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Vivamus vestibulum sagittis sapien. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.\n\nEtiam vel augue. Vestibulum rutrum rutrum neque. Aenean auctor gravida sem.', - points: 0, - is_shown: true, - user_id: 17, -}, { - id: 11, - title: 'Product Engineer', - description: 'Duis bibendum, felis sed interdum venenatis, turpis enim blandit mi, in porttitor pede justo eu massa. Donec dapibus. Duis at velit eu est congue elementum.', - points: 4, - is_shown: false, - user_id: 3, -}, { - id: 12, - title: 'Sales Representative', - description: 'Maecenas tristique, est et tempus semper, est quam pharetra magna, ac consequat metus sapien ut nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris viverra diam vitae quam. Suspendisse potenti.\n\nNullam porttitor lacus at turpis. Donec posuere metus vitae ipsum. Aliquam non mauris.\n\nMorbi non lectus. Aliquam sit amet diam in magna bibendum imperdiet. Nullam orci pede, venenatis non, sodales sed, tincidunt eu, felis.', - points: 1, - is_shown: true, - user_id: 12, -}, { - id: 13, - title: 'Senior Quality Engineer', - description: 'Mauris enim leo, rhoncus sed, vestibulum sit amet, cursus id, turpis. Integer aliquet, massa id lobortis convallis, tortor risus dapibus augue, vel accumsan tellus nisi eu orci. Mauris lacinia sapien quis libero.', - points: 3, - is_shown: false, - user_id: 8, -}, { - id: 14, - title: 'Senior Cost Accountant', - description: 'Sed sagittis. Nam congue, risus semper porta volutpat, quam pede lobortis ligula, sit amet eleifend pede libero quis orci. Nullam molestie nibh in lectus.\n\nPellentesque at nulla. Suspendisse potenti. Cras in purus eu magna vulputate luctus.', - points: 5, - is_shown: false, - user_id: 16, -}, { - id: 15, - title: 'Nurse', - description: 'Maecenas ut massa quis augue luctus tincidunt. Nulla mollis molestie lorem. Quisque ut erat.', - points: 5, - is_shown: false, - user_id: 7, -}, { - id: 16, - title: 'Assistant Manager', - description: 'Aenean lectus. Pellentesque eget nunc. Donec quis orci eget orci vehicula condimentum.\n\nCurabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.', - points: 2, - is_shown: false, - user_id: 18, -}, { - id: 17, - title: 'Information Systems Manager', - description: 'Integer ac leo. Pellentesque ultrices mattis odio. Donec vitae nisi.', - points: 1, - is_shown: true, - user_id: 13, -}, { - id: 18, - title: 'Statistician I', - description: 'Fusce consequat. Nulla nisl. Nunc nisl.\n\nDuis bibendum, felis sed interdum venenatis, turpis enim blandit mi, in porttitor pede justo eu massa. Donec dapibus. Duis at velit eu est congue elementum.', - points: 2, - is_shown: false, - user_id: 13, -}, { - id: 19, - title: 'Senior Developer', - description: 'Maecenas tristique, est et tempus semper, est quam pharetra magna, ac consequat metus sapien ut nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris viverra diam vitae quam. Suspendisse potenti.', - points: 0, - is_shown: true, - user_id: 8, -}, { - id: 20, - title: 'General Manager', - description: 'Nam ultrices, libero non mattis pulvinar, nulla pede ullamcorper augue, a suscipit nulla elit ac nulla. Sed vel enim sit amet nunc viverra dapibus. Nulla suscipit ligula in lacus.', - points: 3, - is_shown: true, - user_id: 4, -}]; +const Reviews = [ + { + title: 'ادارة رائعة', + description: 'يوجد في البرج ادارة قادرة على ادارة جميع خدمات البرج بكفائة', + points: 2, + is_shown: true, + user_id: 2, + }, + { + title: 'حارس أمين', + description: 'يود في البرج حارس أمين يخدم السكان', + points: 0, + is_shown: true, + user_id: 3, + }, + { + title: 'خدمة سيئة', + description: 'خدمات البرج سيئة و يفتقر للنظافة', + points: 2, + is_shown: false, + user_id: 4, + }, +]; -const Transactions = [{ - title: 'DeveloperI', - description: 'Maecenas leo odio, condimentum id, luctus nec, molestie sed, justo. Pellentesque viverra pede ac diam. Cras pellentesque volutpat dui.Maecenas tristique, est et tempus semper, est quam pharetra magna, ac consequat metus sapien ut nunc. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Mauris viverra diam vitae quam. Suspendisse potenti.', - user_id: 8, -}, -{ - title: 'SeniorEditor', - description: 'Aenean lectus. Pellentesque eget nunc. Donec quis orci eget orci vehicula condimentum.Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.', - user_id: 9, -}, +const Payments = [ + { + title: 'دفع فاتورة', + description: + 'لقد قمت بدفع فاتورة بقيمة 80 شيكل', + user_id: 4, + }, + { + title: 'دفع فاتورة', + description: + 'لقد قمت بدفع فاتورة بقيمة 70 شيكل', + user_id: 3, + }, + { + title: 'دفع فاتورة', + description: + 'لقد قمت بدفع فاتورة بقيمة 90 شيكل', + user_id: 5, + }, ]; const Announcements = [ { - title: 'تنبيه لسكان البرج الكرام: فصل الطاقة الشمسية على الساعة السابعة مساء اليوم', + title: + 'تنبيه لسكان البرج الكرام: فصل الطاقة الشمسية على الساعة السابعة مساء اليوم', start_date: '20/10/2022', end_date: '21/10/2022', }, { - title: ' تنبيه لسكان البرج الكرام: نعلمكم بأنه سيتم اليوم اغلاق المصعد لأغراض الصيانة على الساعة السادسة مساء لمدة ساعة', + title: + ' تنبيه لسكان البرج الكرام: نعلمكم بأنه سيتم اليوم اغلاق المصعد لأغراض الصيانة على الساعة السادسة مساء لمدة ساعة', start_date: '20/10/2022', end_date: '21/10/2022', }, { - title: 'اليوم سيتم الاحتفال بذكرى انشاء البرج الثالثة الساعة السابعة مساء على الروف نتمنى حضوركم', + title: + 'اليوم سيتم الاحتفال بذكرى انشاء البرج الثالثة الساعة السابعة مساء على الروف نتمنى حضوركم', start_date: '20/10/2022', end_date: '21/10/2022', }, @@ -335,28 +115,32 @@ const Announcements = [ const Advertisements = [ { title: 'شقة متاحة', - description: ' متاح لدينا شقة فارغة بمساحة 140 متر مربع تحتوي على 3 غرف نوم ومطبخ على الطابق الرابع للمزيد من المعلومات يرجى التواصل', + description: + ' متاح لدينا شقة فارغة بمساحة 140 متر مربع تحتوي على 3 غرف نوم ومطبخ على الطابق الرابع للمزيد من المعلومات يرجى التواصل', start_date: '20/10/2022', end_date: '30/10/2022', - image: 'https://images.pexels.com/photos/7534561/pexels-photo-7534561.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940', + image: + 'https://images.pexels.com/photos/7534561/pexels-photo-7534561.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940', }, { title: 'مطلوب عامل نظافة', description: 'البرج بحاجة الى عامل نظافة براتب 800 شيكل شهريا ', start_date: '20/10/2022', end_date: '30/10/2022', - image: 'https://images.pexels.com/photos/6197123/pexels-photo-6197123.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1', + image: + 'https://images.pexels.com/photos/6197123/pexels-photo-6197123.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1', }, { title: 'شقة متاحة ', - description: 'متاح لدينا شقة فارغة بمساحة 190 متر مربع تحتوي على 3 غرف نوم ومطبخ على الطابق الخامس للمزيد من المعلومات يرجى التواصل', + description: + 'متاح لدينا شقة فارغة بمساحة 190 متر مربع تحتوي على 3 غرف نوم ومطبخ على الطابق الخامس للمزيد من المعلومات يرجى التواصل', start_date: '20/10/2022', end_date: '30/10/2022', - image: 'https://images.pexels.com/photos/5417293/pexels-photo-5417293.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500', + image: + 'https://images.pexels.com/photos/5417293/pexels-photo-5417293.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500', }, - ]; export { - Announcements, Advertisements, Users, Reviews, Transactions, + Announcements, Advertisements, Users, Reviews, Payments, }; diff --git a/server/models/Transaction.ts b/server/models/Payment.ts similarity index 84% rename from server/models/Transaction.ts rename to server/models/Payment.ts index 3a03a95..5ed6045 100644 --- a/server/models/Transaction.ts +++ b/server/models/Payment.ts @@ -3,8 +3,8 @@ import { } from 'sequelize'; import sequelize from '../database/config/connection'; -const Transaction = sequelize.define( - 'Processes', +const Payment = sequelize.define( + 'Payments', { id: { type: DataTypes.INTEGER, @@ -26,4 +26,4 @@ const Transaction = sequelize.define( }, ); -export default Transaction; +export default Payment; diff --git a/server/models/index.ts b/server/models/index.ts index a9723a6..ad8abf8 100644 --- a/server/models/index.ts +++ b/server/models/index.ts @@ -1,6 +1,19 @@ -export { default as Transaction } from './Transaction'; -export { default as Review } from './Review'; -export { default as User } from './User'; +import Payment from './Payment'; +import Review from './Review'; +import User from './User'; +import Announcement from './Announcement'; +import Advertisement from './Advertisement'; -export { default as Announcement } from './Announcement'; -export { default as Advertisement } from './Advertisement'; +Payment.hasOne(User, { + foreignKey: 'user_id', +}); +User.belongsTo(Payment); + +Review.hasOne(User, { + foreignKey: 'user_id', +}); +User.belongsTo(Review); + +export { + Payment, Review, User, Announcement, Advertisement, +}; From 69839803341dc5ee3dc3c58543692ad90eb1ae58 Mon Sep 17 00:00:00 2001 From: Muhammad Abdulhadi Date: Sun, 16 Oct 2022 10:46:30 +0300 Subject: [PATCH 08/12] Update fake data variables --- server/database/config/build.ts | 12 ++++++------ server/database/config/fakeData.ts | 12 ++++++------ server/models/Advertisement.ts | 2 +- server/models/Payment.ts | 2 +- server/models/User.ts | 2 +- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/server/database/config/build.ts b/server/database/config/build.ts index 7c88cdc..ade0a6c 100644 --- a/server/database/config/build.ts +++ b/server/database/config/build.ts @@ -1,7 +1,7 @@ import sequelize from './connection'; import { - Announcements, Advertisements, Users, Reviews, Payments, + announcements, advertisements, users, reviews, payments, } from './fakeData'; @@ -12,11 +12,11 @@ import { const insertDB = async () => { try { await sequelize.sync({ force: true }); - await Announcement.bulkCreate(Announcements); - await Advertisement.bulkCreate(Advertisements); - await User.bulkCreate(Users); - await Review.bulkCreate(Reviews); - await Payment.bulkCreate(Payments); + await Announcement.bulkCreate(announcements); + await Advertisement.bulkCreate(advertisements); + await User.bulkCreate(users); + await Review.bulkCreate(reviews); + await Payment.bulkCreate(payments); // eslint-disable-next-line no-console console.log('Build Database Successfully'); diff --git a/server/database/config/fakeData.ts b/server/database/config/fakeData.ts index d0fca96..0399bea 100644 --- a/server/database/config/fakeData.ts +++ b/server/database/config/fakeData.ts @@ -1,4 +1,4 @@ -const Users = [ +const users = [ { id: 1, first_name: 'أحمد', @@ -46,7 +46,7 @@ const Users = [ }, ]; -const Reviews = [ +const reviews = [ { title: 'ادارة رائعة', description: 'يوجد في البرج ادارة قادرة على ادارة جميع خدمات البرج بكفائة', @@ -70,7 +70,7 @@ const Reviews = [ }, ]; -const Payments = [ +const payments = [ { title: 'دفع فاتورة', description: @@ -91,7 +91,7 @@ const Payments = [ }, ]; -const Announcements = [ +const announcements = [ { title: 'تنبيه لسكان البرج الكرام: فصل الطاقة الشمسية على الساعة السابعة مساء اليوم', @@ -112,7 +112,7 @@ const Announcements = [ }, ]; -const Advertisements = [ +const advertisements = [ { title: 'شقة متاحة', description: @@ -142,5 +142,5 @@ const Advertisements = [ ]; export { - Announcements, Advertisements, Users, Reviews, Payments, + announcements, advertisements, users, reviews, payments, }; diff --git a/server/models/Advertisement.ts b/server/models/Advertisement.ts index 0b961c5..afde97e 100644 --- a/server/models/Advertisement.ts +++ b/server/models/Advertisement.ts @@ -1,7 +1,7 @@ import { DataTypes } from 'sequelize'; import sequelize from '../database/config/connection'; -const Advertisement = sequelize.define('Advertisements', { +const Advertisement = sequelize.define('Advertisement', { id: { primaryKey: true, autoIncrement: true, diff --git a/server/models/Payment.ts b/server/models/Payment.ts index 5ed6045..d8af4b5 100644 --- a/server/models/Payment.ts +++ b/server/models/Payment.ts @@ -4,7 +4,7 @@ import { import sequelize from '../database/config/connection'; const Payment = sequelize.define( - 'Payments', + 'Payment', { id: { type: DataTypes.INTEGER, diff --git a/server/models/User.ts b/server/models/User.ts index 718e2b3..5996990 100644 --- a/server/models/User.ts +++ b/server/models/User.ts @@ -4,7 +4,7 @@ import { import sequelize from '../database/config/connection'; const User = sequelize.define( - 'Transactions', + 'User', { id: { type: DataTypes.INTEGER, From 28aed4f181e0be9f4355b796c79bc12a79f018bd Mon Sep 17 00:00:00 2001 From: mohjaps Date: Sun, 16 Oct 2022 11:22:30 +0300 Subject: [PATCH 09/12] Fix Realships --- server/database/config/build.ts | 5 ++-- server/database/config/fakeData.ts | 38 +++++---------------------- server/models/Review.ts | 41 ------------------------------ server/models/User.ts | 2 +- server/models/index.ts | 10 +++----- 5 files changed, 13 insertions(+), 83 deletions(-) delete mode 100644 server/models/Review.ts diff --git a/server/database/config/build.ts b/server/database/config/build.ts index ade0a6c..4a91a41 100644 --- a/server/database/config/build.ts +++ b/server/database/config/build.ts @@ -1,12 +1,12 @@ import sequelize from './connection'; import { - announcements, advertisements, users, reviews, payments, + announcements, advertisements, users, payments, } from './fakeData'; import { - Announcement, Advertisement, Review, User, Payment, + Announcement, Advertisement, User, Payment, } from '../../models'; const insertDB = async () => { @@ -15,7 +15,6 @@ const insertDB = async () => { await Announcement.bulkCreate(announcements); await Advertisement.bulkCreate(advertisements); await User.bulkCreate(users); - await Review.bulkCreate(reviews); await Payment.bulkCreate(payments); // eslint-disable-next-line no-console diff --git a/server/database/config/fakeData.ts b/server/database/config/fakeData.ts index 0399bea..1e4552a 100644 --- a/server/database/config/fakeData.ts +++ b/server/database/config/fakeData.ts @@ -5,7 +5,7 @@ const users = [ last_name: 'سعيد', email: 'jcotte0@people.com.cn', phone_number: '0591000100', - roles: 'ADMIN', + roles: 'admin', hased_password: '$2y$10$MKpnqAAinu5wjl/MYRc3U.XApWTaEexvI4DMaJA.XZTou5lvpSPfu', }, { @@ -13,8 +13,8 @@ const users = [ first_name: 'خالد', last_name: 'عمر', email: 'gbelt1@thetimes.co.uk', - phone_number: '235-783-1177', - roles: 'USER', + phone_number: '0591000200', + roles: 'user', hased_password: '$2y$10$ROMcXqVNwbepoV6ZdTsTa.6/iego9a72vzSK70pF/S8Oxe/y8tLeO', }, { @@ -23,7 +23,7 @@ const users = [ last_name: 'عبد الله', email: 'tlobe2@angelfire.com', phone_number: '498-722-9258', - roles: 'USER', + roles: 'user', hased_password: '$2y$10$NrRa5y454oIukcfU/iNDruP2iEJPm9UGlHqyhZiyd5mY1fy2vULkG', }, { @@ -32,7 +32,7 @@ const users = [ last_name: 'محمد', email: 'mgravey3@slideshare.net', phone_number: '172-408-5906', - roles: 'USER', + roles: 'user', hased_password: '$2y$10$dOSPYdqciJCM9U10HiWtCOg9j6jpMD69rMPV/2LI/dDL4SxLATkNG', }, { @@ -41,35 +41,11 @@ const users = [ last_name: 'سليم', email: 'cscogin4@nytimes.com', phone_number: '910-220-7086', - roles: 'USER', + roles: 'user', hased_password: '$2y$10$6Y1AcLQDLM7vSSu1A5dj9e61YgCFACEXoBP3NxJ4qX/1SeUUXLFtm', }, ]; -const reviews = [ - { - title: 'ادارة رائعة', - description: 'يوجد في البرج ادارة قادرة على ادارة جميع خدمات البرج بكفائة', - points: 2, - is_shown: true, - user_id: 2, - }, - { - title: 'حارس أمين', - description: 'يود في البرج حارس أمين يخدم السكان', - points: 0, - is_shown: true, - user_id: 3, - }, - { - title: 'خدمة سيئة', - description: 'خدمات البرج سيئة و يفتقر للنظافة', - points: 2, - is_shown: false, - user_id: 4, - }, -]; - const payments = [ { title: 'دفع فاتورة', @@ -142,5 +118,5 @@ const advertisements = [ ]; export { - announcements, advertisements, users, reviews, payments, + announcements, advertisements, users, payments, }; diff --git a/server/models/Review.ts b/server/models/Review.ts deleted file mode 100644 index fe9b73a..0000000 --- a/server/models/Review.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { - DataTypes, -} from 'sequelize'; -import sequelize from '../database/config/connection'; - -const Review = sequelize.define( - 'Reviews', - { - id: { - type: DataTypes.INTEGER, - autoIncrement: true, - primaryKey: true, - }, - title: { - type: DataTypes.STRING, - allowNull: false, - }, - description: { - type: DataTypes.TEXT, - allowNull: true, - }, - points: { - type: DataTypes.INTEGER, - allowNull: false, - validate: { - min: 0, - max: 5, - }, - }, - is_shown: { - type: DataTypes.BOOLEAN, - allowNull: false, - }, - user_id: { - type: DataTypes.INTEGER, - allowNull: false, - }, - }, -); - -export default Review; diff --git a/server/models/User.ts b/server/models/User.ts index 5996990..1b84052 100644 --- a/server/models/User.ts +++ b/server/models/User.ts @@ -32,7 +32,7 @@ const User = sequelize.define( allowNull: false, }, roles: { - type: DataTypes.ENUM('ADMIN', 'USER'), + type: DataTypes.ENUM('admin', 'user'), allowNull: false, }, hased_password: { diff --git a/server/models/index.ts b/server/models/index.ts index ad8abf8..637a021 100644 --- a/server/models/index.ts +++ b/server/models/index.ts @@ -1,19 +1,15 @@ import Payment from './Payment'; -import Review from './Review'; import User from './User'; import Announcement from './Announcement'; import Advertisement from './Advertisement'; -Payment.hasOne(User, { +User.hasMany(Payment, { foreignKey: 'user_id', }); -User.belongsTo(Payment); - -Review.hasOne(User, { +Payment.belongsTo(User, { foreignKey: 'user_id', }); -User.belongsTo(Review); export { - Payment, Review, User, Announcement, Advertisement, + Payment, User, Announcement, Advertisement, }; From 19e8085ace710bba82f281bc5134a5f3856d8176 Mon Sep 17 00:00:00 2001 From: mohjaps Date: Sun, 16 Oct 2022 15:10:53 +0300 Subject: [PATCH 10/12] Solve Relationships --- server/database/config/build.ts | 4 ++-- server/database/config/fakeData.ts | 22 +++++++++++----------- server/models/Payment.ts | 4 ---- server/models/index.ts | 25 ++++++------------------- 4 files changed, 19 insertions(+), 36 deletions(-) diff --git a/server/database/config/build.ts b/server/database/config/build.ts index 643cafd..5bf8170 100644 --- a/server/database/config/build.ts +++ b/server/database/config/build.ts @@ -13,11 +13,11 @@ const insertDB = async () => { await sequelize.sync({ force: true }); await AnnouncementModel.bulkCreate(announcements); await AdvertisementModel.bulkCreate(advertisements); + await ServiceModel.bulkCreate(services); await UserModel.bulkCreate(users); - await PaymentModel.bulkCreate(payments); await FlatModel.bulkCreate(flats); await BillModel.bulkCreate(bills); - await ServiceModel.bulkCreate(services); + await PaymentModel.bulkCreate(payments); // eslint-disable-next-line no-console console.log('Build Database Successfully'); diff --git a/server/database/config/fakeData.ts b/server/database/config/fakeData.ts index 304e718..6b169eb 100644 --- a/server/database/config/fakeData.ts +++ b/server/database/config/fakeData.ts @@ -51,19 +51,19 @@ const payments = [ title: 'دفع فاتورة', description: 'لقد قمت بدفع فاتورة بقيمة 80 شيكل', - user_id: 4, + BillId: 4, }, { title: 'دفع فاتورة', description: 'لقد قمت بدفع فاتورة بقيمة 70 شيكل', - user_id: 3, + BillId: 3, }, { title: 'دفع فاتورة', description: 'لقد قمت بدفع فاتورة بقيمة 90 شيكل', - user_id: 5, + BillId: 1, }, ]; @@ -158,7 +158,7 @@ const services = [ const bills = [ { total_price: 315, - flat_id: 1, + FlatId: 1, is_open: true, services: [ { @@ -200,7 +200,7 @@ const bills = [ }, { total_price: 370, - flat_id: 2, + FlatId: 2, is_open: true, services: [ { @@ -242,7 +242,7 @@ const bills = [ }, { total_price: 255, - flat_id: 3, + FlatId: 3, is_open: true, services: [ { @@ -284,7 +284,7 @@ const bills = [ }, { total_price: 355, - flat_id: 4, + FlatId: 4, is_open: true, services: [ { @@ -333,28 +333,28 @@ const flats = [ area: 180, notes: 'شقة غربية', is_active: true, - owner_id: 1, + UserId: 1, }, { flat_number: 102, area: 160, notes: 'شقة جنوبية', is_active: true, - owner_id: 2, + UserId: 2, }, { flat_number: 103, area: 120, notes: 'شقة شرقية', is_active: true, - owner_id: 3, + UserId: 3, }, { flat_number: 104, area: 180, notes: 'شقة شمالية', is_active: true, - owner_id: 4, + UserId: 4, }, ]; diff --git a/server/models/Payment.ts b/server/models/Payment.ts index d8af4b5..ab9140c 100644 --- a/server/models/Payment.ts +++ b/server/models/Payment.ts @@ -19,10 +19,6 @@ const Payment = sequelize.define( type: DataTypes.TEXT, allowNull: true, }, - user_id: { - type: DataTypes.INTEGER, - allowNull: false, - }, }, ); diff --git a/server/models/index.ts b/server/models/index.ts index f925a1b..917b700 100644 --- a/server/models/index.ts +++ b/server/models/index.ts @@ -6,27 +6,14 @@ import AnnouncementModel from './Announcement'; import BillModel from './Bill'; import ServiceModel from './Service'; -FlatModel.hasMany(BillModel, { - foreignKey: 'flat_id', -}); +FlatModel.hasMany(BillModel); +BillModel.belongsTo(FlatModel); -BillModel.belongsTo(FlatModel, { - foreignKey: 'flat_id', -}); +UserModel.hasMany(FlatModel); +FlatModel.belongsTo(UserModel); -UserModel.hasMany(FlatModel, { - foreignKey: 'owner_id', -}); -FlatModel.belongsTo(UserModel, { - foreignKey: 'owner_id', -}); - -UserModel.hasMany(PaymentModel, { - foreignKey: 'user_id', -}); -PaymentModel.belongsTo(UserModel, { - foreignKey: 'user_id', -}); +BillModel.hasMany(PaymentModel); +PaymentModel.belongsTo(BillModel); export { PaymentModel, UserModel, BillModel, FlatModel, ServiceModel, AnnouncementModel, From c7cbe2e94dcd94b055c525e8a1b6dd4d3cffbca9 Mon Sep 17 00:00:00 2001 From: mohjaps Date: Sun, 16 Oct 2022 15:38:59 +0300 Subject: [PATCH 11/12] Complaints_User Relationship --- server/database/config/fakeData.ts | 6 +++--- server/models/index.ts | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/server/database/config/fakeData.ts b/server/database/config/fakeData.ts index 6372f0d..a125e58 100644 --- a/server/database/config/fakeData.ts +++ b/server/database/config/fakeData.ts @@ -122,19 +122,19 @@ const complaints = [ title: 'شكوى رقم 1', description: 'تفاصيل الشكوى', is_solved: true, - user_id: 1, + UserId: 1, }, { title: 'شكوى رقم 2', description: 'تفاصيل الشكوى', is_solved: true, - user_id: 2, + UserId: 2, }, { title: 'شكوى رقم 3', description: 'تفاصيل الشكوى', is_solved: true, - user_id: 3, + UserId: 3, }, ]; diff --git a/server/models/index.ts b/server/models/index.ts index 89f3e0a..640bd14 100644 --- a/server/models/index.ts +++ b/server/models/index.ts @@ -17,6 +17,9 @@ FlatModel.belongsTo(UserModel); BillModel.hasMany(PaymentModel); PaymentModel.belongsTo(BillModel); +UserModel.hasMany(ComplaintsModel); +ComplaintsModel.belongsTo(UserModel); + export { PaymentModel, UserModel, BillModel, FlatModel, ServiceModel, AnnouncementModel, AdvertisementModel, ComplaintsModel, ContactUsModel, From ed1b695996fa7f925dfa976eb0aeb709670b6512 Mon Sep 17 00:00:00 2001 From: mohjaps Date: Sun, 16 Oct 2022 15:41:57 +0300 Subject: [PATCH 12/12] User Roles --- server/database/config/fakeData.ts | 10 +++++----- server/models/User.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/database/config/fakeData.ts b/server/database/config/fakeData.ts index a125e58..d35d909 100644 --- a/server/database/config/fakeData.ts +++ b/server/database/config/fakeData.ts @@ -5,7 +5,7 @@ const users = [ last_name: 'سعيد', email: 'jcotte0@people.com.cn', phone_number: '0591000100', - roles: 'admin', + role: 'admin', hased_password: '$2y$10$MKpnqAAinu5wjl/MYRc3U.XApWTaEexvI4DMaJA.XZTou5lvpSPfu', }, { @@ -14,7 +14,7 @@ const users = [ last_name: 'عمر', email: 'gbelt1@thetimes.co.uk', phone_number: '0591000200', - roles: 'user', + role: 'user', hased_password: '$2y$10$ROMcXqVNwbepoV6ZdTsTa.6/iego9a72vzSK70pF/S8Oxe/y8tLeO', }, { @@ -23,7 +23,7 @@ const users = [ last_name: 'عبد الله', email: 'tlobe2@angelfire.com', phone_number: '498-722-9258', - roles: 'user', + role: 'user', hased_password: '$2y$10$NrRa5y454oIukcfU/iNDruP2iEJPm9UGlHqyhZiyd5mY1fy2vULkG', }, { @@ -32,7 +32,7 @@ const users = [ last_name: 'محمد', email: 'mgravey3@slideshare.net', phone_number: '172-408-5906', - roles: 'user', + role: 'user', hased_password: '$2y$10$dOSPYdqciJCM9U10HiWtCOg9j6jpMD69rMPV/2LI/dDL4SxLATkNG', }, { @@ -41,7 +41,7 @@ const users = [ last_name: 'سليم', email: 'cscogin4@nytimes.com', phone_number: '910-220-7086', - roles: 'user', + role: 'user', hased_password: '$2y$10$6Y1AcLQDLM7vSSu1A5dj9e61YgCFACEXoBP3NxJ4qX/1SeUUXLFtm', }, ]; diff --git a/server/models/User.ts b/server/models/User.ts index 1b84052..421cbb9 100644 --- a/server/models/User.ts +++ b/server/models/User.ts @@ -31,7 +31,7 @@ const User = sequelize.define( unique: true, allowNull: false, }, - roles: { + role: { type: DataTypes.ENUM('admin', 'user'), allowNull: false, },