-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hadiqa11
committed
Oct 4, 2023
1 parent
6e89ed0
commit 3848c1a
Showing
32 changed files
with
821 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# .env | ||
|
||
NODE_ENV= | ||
DB_HOST= | ||
DB_DIALECT= | ||
DB_USER= | ||
DB_PASSWORD= | ||
DB_PORT= | ||
DB_MIGRATIONS_PATH= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
node_modules | ||
node_modules | ||
.env | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"development": { | ||
"host": "localhost", | ||
"dialect": "postgres", | ||
"user":"hadiqasumbalarshad", | ||
"password" :"11223344", | ||
"port":"5432", | ||
"migrationsPath": "./migrations" | ||
|
||
}, | ||
"test": { | ||
"host": "localhost", | ||
"dialect": "postgres", | ||
"user":"hadiqasumbalarshad", | ||
"password" :"11223344", | ||
"port":"5432" | ||
}, | ||
"production": { | ||
"host": "localhost", | ||
"dialect": "postgres", | ||
"user":"hadiqasumbalarshad", | ||
"password" :"11223344", | ||
"port":"5432" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Request, Response } from 'express'; | ||
// import AttachmentService from '../services/attachment.service'; | ||
|
||
// Function to create a new attachment | ||
const createAttachment = async (req: Request, res: Response) => { | ||
try { | ||
const { fileUrl, fileName, messageId, creatorId } = req.body; | ||
const attachment = await AttachmentService.createAttachment( | ||
fileUrl, | ||
fileName, | ||
messageId, | ||
creatorId | ||
); | ||
|
||
res.status(201).json(attachment); | ||
} catch (error) { | ||
res.status(500).json({ error: error.message }); | ||
} | ||
}; | ||
|
||
// Function to get attachments by message ID | ||
const getAttachmentsByMessageId = async (req: Request, res: Response) => { | ||
try { | ||
const { message_id } = req.params; | ||
const attachments = await AttachmentService.getAttachmentsByMessageId( | ||
message_id | ||
); | ||
|
||
res.status(200).json(attachments); | ||
} catch (error) { | ||
res.status(500).json({ error: error.message }); | ||
} | ||
}; | ||
|
||
export { createAttachment, getAttachmentsByMessageId }; |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
import { QueryInterface, DataTypes, Sequelize } from 'sequelize'; | ||
|
||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up (queryInterface: QueryInterface, sequelize: Sequelize) { | ||
await queryInterface.createTable('Users', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: DataTypes.INTEGER | ||
}, | ||
userName: { | ||
type: DataTypes.STRING | ||
}, | ||
fullName: { | ||
type: DataTypes.STRING | ||
}, | ||
email: { | ||
type: DataTypes.STRING | ||
}, | ||
password: { | ||
type: DataTypes.STRING | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: DataTypes.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: DataTypes.DATE | ||
} | ||
}); | ||
}, | ||
|
||
async down (queryInterface: QueryInterface, sequelize: Sequelize) { | ||
await queryInterface.dropTable('Users'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
|
||
import { QueryInterface, DataTypes, Sequelize } from 'sequelize'; | ||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up (queryInterface: QueryInterface, sequelize: Sequelize) { | ||
await queryInterface.createTable('Messages', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: DataTypes.INTEGER | ||
}, | ||
text: { | ||
type: DataTypes.STRING, | ||
allowNull: false | ||
}, | ||
sender_id : { | ||
type: DataTypes.INTEGER.UNSIGNED , | ||
allowNull: false, | ||
}, | ||
group_id : { | ||
type: DataTypes.INTEGER.UNSIGNED , | ||
allowNull: false, | ||
}, | ||
reciever_id : { | ||
type: DataTypes.INTEGER.UNSIGNED , | ||
allowNull: false, | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: DataTypes.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: DataTypes.DATE | ||
} | ||
}); | ||
}, | ||
|
||
async down (queryInterface: QueryInterface, sequelize: Sequelize) { | ||
await queryInterface.dropTable('Messages'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict'; | ||
|
||
import { QueryInterface, DataTypes, Sequelize } from 'sequelize'; | ||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up (queryInterface: QueryInterface, sequelize: Sequelize) { | ||
await queryInterface.createTable('Groups', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: DataTypes.INTEGER | ||
}, | ||
group_name: { | ||
allowNull: false, | ||
type: DataTypes.STRING | ||
}, | ||
creator_id : { | ||
type: DataTypes.INTEGER.UNSIGNED , | ||
allowNull: false, | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: DataTypes.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: DataTypes.DATE | ||
} | ||
}); | ||
}, | ||
|
||
async down (queryInterface: QueryInterface, sequelize: Sequelize) { | ||
await queryInterface.dropTable('Groups'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
|
||
import { QueryInterface, DataTypes, Sequelize } from 'sequelize'; | ||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up (queryInterface: QueryInterface, sequelize: Sequelize) { | ||
await queryInterface.createTable('Group_participants', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: DataTypes.INTEGER | ||
}, | ||
group_id : { | ||
type: DataTypes.INTEGER.UNSIGNED , | ||
allowNull: false, | ||
}, | ||
|
||
user_id : { | ||
type: DataTypes.INTEGER.UNSIGNED , | ||
allowNull: false, | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: DataTypes.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: DataTypes.DATE | ||
} | ||
}); | ||
}, | ||
|
||
async down (queryInterface: QueryInterface, sequelize: Sequelize) { | ||
await queryInterface.dropTable('Groups'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict'; | ||
|
||
import { QueryInterface, DataTypes, Sequelize } from 'sequelize'; | ||
/** @type {import('sequelize-cli').Migration} */ | ||
module.exports = { | ||
async up (queryInterface: QueryInterface, sequelize: Sequelize) { | ||
await queryInterface.createTable('Attachments', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: DataTypes.INTEGER | ||
}, | ||
file_Url: { | ||
allowNull: false, | ||
type: DataTypes.STRING | ||
}, | ||
file_Name: { | ||
type: DataTypes.STRING | ||
}, | ||
creator_id : { | ||
type: DataTypes.INTEGER.UNSIGNED , | ||
allowNull: false, | ||
}, | ||
message_id : { | ||
type: DataTypes.INTEGER.UNSIGNED , | ||
allowNull: false, | ||
}, | ||
createdAt: { | ||
allowNull: false, | ||
type: DataTypes.DATE | ||
}, | ||
updatedAt: { | ||
allowNull: false, | ||
type: DataTypes.DATE | ||
} | ||
}); | ||
}, | ||
|
||
async down (queryInterface: QueryInterface, sequelize: Sequelize) { | ||
await queryInterface.dropTable('Attachments'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { Sequelize, DataTypes, Model } from 'sequelize'; | ||
|
||
const basename = path.basename(__filename); | ||
const env = process.env.NODE_ENV || 'development'; | ||
const config = require(path.join(__dirname, '..', 'config', 'config.json'))[env]; | ||
const db: Record<string, Model> = {}; // Define the type for the `db` object | ||
|
||
let sequelize: Sequelize; | ||
|
||
// if (config.use_env_variable) { | ||
// sequelize = new Sequelize(process.env[config.use_env_variable]!, config); | ||
// } else { | ||
// sequelize = new Sequelize(config.database!, config.username!, config.password!, config); | ||
// } | ||
|
||
fs | ||
.readdirSync(__dirname) | ||
.filter(file => { | ||
return ( | ||
file.indexOf('.') !== 0 && | ||
file !== basename && | ||
file.slice(-3) === '.ts' && | ||
file.indexOf('.test.ts') === -1 | ||
); | ||
}) | ||
.forEach(file => { | ||
const model = require(path.join(__dirname, file)).default(sequelize, DataTypes); | ||
db[model.name] = model; | ||
}); | ||
|
||
Object.keys(db).forEach((model : any) => { | ||
if (model.associate) { | ||
model.associate!(db); | ||
} | ||
}); | ||
|
||
|
||
export { sequelize, DataTypes }; | ||
|
||
export default db; | ||
|
Oops, something went wrong.