Skip to content

Commit

Permalink
Merge pull request #48 from CA-G12/44-review-transactions-users
Browse files Browse the repository at this point in the history
Init Payments, Reviews and Users Models
  • Loading branch information
Mu7ammadAbed authored Oct 16, 2022
2 parents d18a5d5 + ed1b695 commit 484a73c
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 50 deletions.
18 changes: 14 additions & 4 deletions server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import cookieParser from 'cookie-parser';
import { join } from 'path';
import morgan from 'morgan';
import {
ComplaintsModel, ContactUsModel,
Announcement, Advertisement, BillModel, FlatModel, ServiceModel,
AnnouncementModel, AdvertisementModel, BillModel, FlatModel, ServiceModel, UserModel,
PaymentModel, ComplaintsModel, ContactUsModel,
} from './models';

dotenv.config();
Expand All @@ -29,15 +29,25 @@ if (NODE_ENV === 'development') {
// app.use('/api/v1', router);

app.get('/announcements', async (req, res) => {
const data = await Announcement.findAll();
const data = await AnnouncementModel.findAll();
res.json({ message: 'Announcements', data });
});

app.get('/advertisements', async (req, res) => {
const data = await Advertisement.findAll();
const data = await AdvertisementModel.findAll();
res.json({ message: 'Advertisements', data });
});

app.get('/Users', async (req, res) => {
const data = await UserModel.findAll();
res.json({ message: 'Users', data });
});

app.get('/Payments', async (req, res) => {
const data = await PaymentModel.findAll();
res.json({ message: 'Payments', data });
});

app.get('/bill', async (req, res) => {
const data = await BillModel.findAll();
res.json({
Expand Down
12 changes: 8 additions & 4 deletions server/database/config/build.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import sequelize from './connection';
import {
announcements, advertisements, services, bills, flats, complaints, contactUs,
announcements, advertisements, bills, flats, services, users, payments, complaints, contactUs,
} from './fakeData';

import {
Announcement, Advertisement, BillModel, FlatModel, ServiceModel, ComplaintsModel, ContactUsModel,
AnnouncementModel, AdvertisementModel, BillModel, FlatModel, ServiceModel, UserModel,
PaymentModel, ComplaintsModel, ContactUsModel,
} from '../../models/index';

const insertDB = async () => {
try {
await sequelize.sync({ force: true });
await Announcement.bulkCreate(announcements);
await Advertisement.bulkCreate(advertisements);
await AnnouncementModel.bulkCreate(announcements);
await AdvertisementModel.bulkCreate(advertisements);
await ServiceModel.bulkCreate(services);
await UserModel.bulkCreate(users);
await FlatModel.bulkCreate(flats);
await BillModel.bulkCreate(bills);
await PaymentModel.bulkCreate(payments);
await ServiceModel.bulkCreate(services);
await ComplaintsModel.bulkCreate(complaints);
await ContactUsModel.bulkCreate(contactUs);
Expand Down
119 changes: 98 additions & 21 deletions server/database/config/fakeData.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,88 @@
const users = [
{
id: 1,
first_name: 'أحمد',
last_name: 'سعيد',
email: '[email protected]',
phone_number: '0591000100',
role: 'admin',
hased_password: '$2y$10$MKpnqAAinu5wjl/MYRc3U.XApWTaEexvI4DMaJA.XZTou5lvpSPfu',
},
{
id: 2,
first_name: 'خالد',
last_name: 'عمر',
email: '[email protected]',
phone_number: '0591000200',
role: 'user',
hased_password: '$2y$10$ROMcXqVNwbepoV6ZdTsTa.6/iego9a72vzSK70pF/S8Oxe/y8tLeO',
},
{
id: 3,
first_name: 'سمير',
last_name: 'عبد الله',
email: '[email protected]',
phone_number: '498-722-9258',
role: 'user',
hased_password: '$2y$10$NrRa5y454oIukcfU/iNDruP2iEJPm9UGlHqyhZiyd5mY1fy2vULkG',
},
{
id: 4,
first_name: 'مهند',
last_name: 'محمد',
email: '[email protected]',
phone_number: '172-408-5906',
role: 'user',
hased_password: '$2y$10$dOSPYdqciJCM9U10HiWtCOg9j6jpMD69rMPV/2LI/dDL4SxLATkNG',
},
{
id: 5,
first_name: 'تميم',
last_name: 'سليم',
email: '[email protected]',
phone_number: '910-220-7086',
role: 'user',
hased_password: '$2y$10$6Y1AcLQDLM7vSSu1A5dj9e61YgCFACEXoBP3NxJ4qX/1SeUUXLFtm',
},
];

const payments = [
{
title: 'دفع فاتورة',
description:
'لقد قمت بدفع فاتورة بقيمة 80 شيكل',
BillId: 4,
},
{
title: 'دفع فاتورة',
description:
'لقد قمت بدفع فاتورة بقيمة 70 شيكل',
BillId: 3,
},
{
title: 'دفع فاتورة',
description:
'لقد قمت بدفع فاتورة بقيمة 90 شيكل',
BillId: 1,
},
];

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',
},
Expand All @@ -19,46 +91,50 @@ 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',
},

];

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,
},
];

Expand Down Expand Up @@ -126,7 +202,7 @@ const services = [
const bills = [
{
total_price: 315,
flat_id: 1,
FlatId: 1,
is_open: true,
services: [
{
Expand Down Expand Up @@ -168,7 +244,7 @@ const bills = [
},
{
total_price: 370,
flat_id: 2,
FlatId: 2,
is_open: true,
services: [
{
Expand Down Expand Up @@ -210,7 +286,7 @@ const bills = [
},
{
total_price: 255,
flat_id: 3,
FlatId: 3,
is_open: true,
services: [
{
Expand Down Expand Up @@ -252,7 +328,7 @@ const bills = [
},
{
total_price: 355,
flat_id: 4,
FlatId: 4,
is_open: true,
services: [
{
Expand Down Expand Up @@ -301,31 +377,32 @@ 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,
},
];

export {
announcements, advertisements, services, bills, flats, complaints, contactUs,
announcements, advertisements, services, bills, flats, users, payments,
complaints, contactUs,
};
2 changes: 1 addition & 1 deletion server/models/Advertisement.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
25 changes: 25 additions & 0 deletions server/models/Payment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
DataTypes,
} from 'sequelize';
import sequelize from '../database/config/connection';

const Payment = sequelize.define(
'Payment',
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
title: {
type: DataTypes.STRING,
allowNull: false,
},
description: {
type: DataTypes.TEXT,
allowNull: true,
},
},
);

export default Payment;
48 changes: 48 additions & 0 deletions server/models/User.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {
DataTypes,
} from 'sequelize';
import sequelize from '../database/config/connection';

const User = sequelize.define(
'User',
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
first_name: {
type: DataTypes.STRING,
allowNull: false,
},
last_name: {
type: DataTypes.STRING,
allowNull: false,
},
email: {
type: DataTypes.STRING,
allowNull: true,
validate: {
isEmail: true,
},
},
phone_number: {
type: DataTypes.STRING,
unique: true,
allowNull: false,
},
role: {
type: DataTypes.ENUM('admin', 'user'),
allowNull: false,
},
hased_password: {
type: DataTypes.STRING,
validate: {
is: /^[0-9a-f]{64}$/i,
},
allowNull: false,
},
},
);

export default User;
Loading

0 comments on commit 484a73c

Please sign in to comment.