Skip to content

Commit

Permalink
resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
mohjaps committed Oct 13, 2022
2 parents e709d22 + 0594d27 commit ae2bad3
Show file tree
Hide file tree
Showing 14 changed files with 149 additions and 187 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"test": "cross-env NODE_ENV=test jest -i",
"build": "tsc -p .",
"heroku-postbuild": "npm run build && cd client/ && npm i && npm run build",
"db:seed": "cross-env NODE_ENV=development ts-node server/database/config/build.ts",
"eslint:fix": "eslint --fix",
"lint": "eslint --ext .ts server/ && eslint --ext .tsx client/src/"
},
Expand Down
11 changes: 11 additions & 0 deletions server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dotenv from 'dotenv';
import cookieParser from 'cookie-parser';
import { join } from 'path';
import morgan from 'morgan';
import { Announcement, Advertisement } from './models';

dotenv.config();

Expand All @@ -24,6 +25,16 @@ if (NODE_ENV === 'development') {

// app.use('/api/v1', router);

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

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

if (NODE_ENV === 'production') {
app.use(express.static(join(__dirname, '..', 'client', 'build')));
app.get('*', (req, res) => {
Expand Down
32 changes: 21 additions & 11 deletions server/database/config/build.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import sequelize from './connection';
import
{
Announcements, Advertisements, Users, Reviews, Transactions,
}
from './fakeData';

import {
reviews, transactions, users,
} from './fakeData';
import {
Reviews, Transactions, Users,
Announcement, Advertisement, Review, User, Transaction,
} from '../../models/index';

const dbConnect = () => sequelize.sync();

const insertDB = async () => {
await sequelize.sync({ force: true });
await Users.bulkCreate(users);
await Transactions.bulkCreate(transactions);
await Reviews.bulkCreate(reviews);
try {
await sequelize.sync({ force: true });
await Announcement.bulkCreate(Announcements);
await Advertisement.bulkCreate(Advertisements);
await Review.bulkCreate(Reviews);
await User.bulkCreate(Users);
await Transaction.bulkCreate(Transactions);

// eslint-disable-next-line no-console
console.log('Build Database Successfully');
} catch (err) {
// eslint-disable-next-line no-console
console.log('Build Database Failed', err);
}
};
insertDB();
export default dbConnect;
2 changes: 1 addition & 1 deletion server/database/config/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ switch (NODE_ENV) {
}
if (!url) throw new Error('The database url is invalid!');

const sequelizeConfig = new Sequelize(url);
const sequelizeConfig = new Sequelize(url, { logging: false, dialect: 'postgres' });
export default sequelizeConfig;
51 changes: 47 additions & 4 deletions server/database/config/fakeData.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const users = [{
const Users = [{
id: 1,
first_name: 'Jules',
last_name: 'Cotte',
Expand Down Expand Up @@ -180,7 +180,7 @@ const users = [{
hased_password: 'zgGeNhGc',
}];

const reviews = [{
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.',
Expand Down Expand Up @@ -342,7 +342,7 @@ const reviews = [{
user_id: 4,
}];

const transactions = [{
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.',
Expand Down Expand Up @@ -464,6 +464,49 @@ const transactions = [{
user_id: 9,
}];

const Announcements = [
{
title: 'تنبيه لسكان البرج الكرام: فصل الطاقة الشمسية على الساعة السابعة مساء اليوم',
start_date: '20/10/2022',
end_date: '21/10/2022',
},
{
title: ' تنبيه لسكان البرج الكرام: نعلمكم بأنه سيتم اليوم اغلاق المصعد لأغراض الصيانة على الساعة السادسة مساء لمدة ساعة',
start_date: '20/10/2022',
end_date: '21/10/2022',
},
{
title: 'اليوم سيتم الاحتفال بذكرى انشاء البرج الثالثة الساعة السابعة مساء على الروف نتمنى حضوركم',
start_date: '20/10/2022',
end_date: '21/10/2022',
},
];

const Advertisements = [
{
title: 'شقة متاحة',
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',
},
{
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',
},
{
title: 'شقة متاحة ',
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',
},

];

export {
users, reviews, transactions,
Announcements, Advertisements, Users, Reviews, Transactions,
};
2 changes: 1 addition & 1 deletion server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import sequelize from './database/config/connection';

const port = app.get('port') as number;

sequelize.sync({ force: true }) // TODO: To be reomved later when DB is 100% ready
sequelize.sync()
.then(() => {
app.listen(port, () => {
// eslint-disable-next-line no-console
Expand Down
32 changes: 32 additions & 0 deletions server/models/Advertisement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { DataTypes } from 'sequelize';
import sequelize from '../database/config/connection';

const Advertisement = sequelize.define('Advertisements', {
id: {
primaryKey: true,
autoIncrement: true,
type: DataTypes.INTEGER,
},
title: {
type: DataTypes.STRING,
allowNull: false,
},
description: {
type: DataTypes.STRING,
allowNull: false,
},
start_date: {
type: DataTypes.STRING,
allowNull: false,
},
end_date: {
type: DataTypes.STRING,
allowNull: false,
},
image: {
type: DataTypes.STRING,
allowNull: false,
},
});

export default Advertisement;
51 changes: 0 additions & 51 deletions server/models/Advertisements.ts

This file was deleted.

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

const Announcement = sequelize.define('Announcements', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
title: {
type: DataTypes.STRING,
allowNull: false,
},
start_date: {
type: DataTypes.STRING,
allowNull: false,
},
end_date: {
type: DataTypes.STRING,
allowNull: false,
},
});

export default Announcement;
41 changes: 0 additions & 41 deletions server/models/Announcements.ts

This file was deleted.

28 changes: 2 additions & 26 deletions server/models/reviews.ts → server/models/Review.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,9 @@
import {
Model,
InferAttributes,
InferCreationAttributes,
CreationOptional,
DataTypes,
} from 'sequelize';
import sequelize from '../database/config/connection';

interface ReviewsModel
extends Model<
InferAttributes<ReviewsModel>,
InferCreationAttributes<ReviewsModel>
> {
id: CreationOptional<number>

title?: string

description?: Text

points?: number

is_shown?: boolean

creation_date?: string

user_id?: number
}

const Reviews = sequelize.define<ReviewsModel>(
const Review = sequelize.define(
'Reviews',
{
id: {
Expand Down Expand Up @@ -67,4 +43,4 @@ const Reviews = sequelize.define<ReviewsModel>(
},
);

export default Reviews;
export default Review;
24 changes: 2 additions & 22 deletions server/models/transactions.ts → server/models/Transaction.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
import {
Model,
InferAttributes,
InferCreationAttributes,
CreationOptional,
DataTypes,
} from 'sequelize';
import sequelize from '../database/config/connection';

interface TransactionsModel
extends Model<
InferAttributes<TransactionsModel>,
InferCreationAttributes<TransactionsModel>
> {
id: CreationOptional<number>

title?: string

description?: Text

creation_date?: Date

user_id?: number
}

const Transactions = sequelize.define<TransactionsModel>(
const Transaction = sequelize.define(
'Transactions',
{
id: {
Expand Down Expand Up @@ -51,4 +31,4 @@ const Transactions = sequelize.define<TransactionsModel>(
},
);

export default Transactions;
export default Transaction;
Loading

0 comments on commit ae2bad3

Please sign in to comment.