-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into feat/9-Help_Center_Update_Topic
- Loading branch information
Showing
30 changed files
with
577 additions
and
310 deletions.
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 |
---|---|---|
@@ -1,6 +1,12 @@ | ||
port=8000 | ||
PORT=8000 | ||
AUTH_SECRET= | ||
DB_USER= | ||
DB_HOST= | ||
DB_PASSWORD= | ||
DB_NAME= | ||
DB_NAME= | ||
NODE_ENV=development | ||
SMTP_USER= | ||
SMTP_PASSWORD= | ||
SMTP_HOST= | ||
SMTP_SERVICE= | ||
|
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
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,11 @@ | ||
import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
||
export class Migration1721611425287 implements MigrationInterface { | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
} | ||
|
||
} |
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
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
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
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,96 @@ | ||
import { NotificationSetting } from "../models/notification"; | ||
import { Request, Response } from "express"; | ||
|
||
// TO validate all required fields in post /api/notification-settings | ||
interface NotificationSettings { | ||
user_id: number; | ||
email_notifications: boolean; | ||
push_notifications: boolean; | ||
sms_notifications: boolean; | ||
} | ||
|
||
const requiredFields: (keyof NotificationSettings)[] = [ | ||
"user_id", | ||
"email_notifications", | ||
"push_notifications", | ||
"sms_notifications", | ||
]; | ||
const validateFields = (body: Partial<NotificationSettings>) => { | ||
const missingFields = requiredFields.filter( | ||
(field) => body[field] === undefined | ||
); | ||
|
||
if (missingFields.length > 0) { | ||
return { | ||
valid: false, | ||
message: `Missing required fields: ${missingFields.join(", ")}`, | ||
}; | ||
} | ||
|
||
return { valid: true }; | ||
}; | ||
|
||
// Create notification setting for a user | ||
const CreateNotification = async (req: Request, res: Response) => { | ||
try { | ||
const validation = validateFields(req.body); | ||
|
||
if (!validation.valid) { | ||
return res | ||
.status(400) | ||
.json({ status: "error", code: 400, message: validation.message }); | ||
} | ||
const { user_id } = req.body; | ||
|
||
// Check if a notification setting already exists for this user_id | ||
const existingSetting = await NotificationSetting.findOne({ | ||
where: { user_id }, | ||
}); | ||
|
||
const newSetting = NotificationSetting.create(req.body); | ||
const result = await NotificationSetting.save(newSetting); | ||
res.status(200).json({ status: "success", code: 200, data: result }); | ||
|
||
if (existingSetting) { | ||
return res | ||
.status(409) | ||
.json({ | ||
status: "error", | ||
code: 409, | ||
message: "Notification settings for this user already exist.", | ||
}); | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
res | ||
.status(500) | ||
.json({ | ||
status: "error", | ||
code: 500, | ||
message: "Error creating user notification", | ||
}); | ||
} | ||
}; | ||
|
||
// Get notification setting | ||
const GetNotification = async (req: Request, res: Response) => { | ||
try { | ||
const settings = await NotificationSetting.findOne({ | ||
where: { user_id: String(req.params.user_id) }, | ||
}); | ||
if (settings === null) { | ||
return res | ||
.status(404) | ||
.json({ | ||
status: "Not found", | ||
message: "The user with the requested id cannot be found", | ||
}); | ||
} | ||
res.status(200).json({ status: "success", code: 200, data: settings }); | ||
} catch (error) { | ||
res.status(500).json({ status: "error", code: 500, message: error.message }); | ||
} | ||
}; | ||
|
||
|
||
export { CreateNotification, GetNotification }; |
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,34 @@ | ||
import { Request, Response } from "express"; | ||
import { OrgService } from "../services/OrgService"; | ||
|
||
export class OrgController { | ||
private orgService: OrgService; | ||
constructor() { | ||
this.orgService = new OrgService(); | ||
} | ||
|
||
async removeUser(req: Request, res: Response) { | ||
try { | ||
const user = await this.orgService.removeUser( | ||
req.params.org_id, | ||
req.params.user_id, | ||
); | ||
if (!user) { | ||
return res.status(404).json({ | ||
status: "forbidden", | ||
message: "User not found in the organization", | ||
status_code: 404, | ||
}); | ||
} | ||
res.status(200).json({ | ||
status: "success", | ||
message: "User deleted succesfully", | ||
status_code: 200, | ||
}); | ||
} catch (error) { | ||
res | ||
.status(400) | ||
.json({ message: "Failed to remove user from organization" }); | ||
} | ||
} | ||
} |
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,46 @@ | ||
import { Request, Response } from "express"; | ||
import SmsService from "../services/sms.services"; | ||
import AppDataSource from "../data-source"; | ||
import { User } from "../models"; | ||
|
||
export const sendSms = async (req: Request, res: Response): Promise<void> => { | ||
const { phone_number, message } = req.body; | ||
const sender_id = req.user.id; | ||
|
||
if (!phone_number || !message || !sender_id) { | ||
res.status(400).json({ | ||
status: "unsuccessful", | ||
status_code: 400, | ||
message: | ||
"Valid phone number, message content, and sender ID must be provided.", | ||
}); | ||
return; | ||
} | ||
|
||
try { | ||
const userRepository = AppDataSource.getRepository(User); | ||
const sender = await userRepository.findOneBy({ id: sender_id }); | ||
|
||
if (!sender) { | ||
res.status(404).json({ | ||
status: "unsuccessful", | ||
status_code: 404, | ||
message: "Sender not found.", | ||
}); | ||
return; | ||
} | ||
|
||
await SmsService.sendSms(sender, phone_number, message); | ||
res.status(200).json({ | ||
status: "success", | ||
status_code: 200, | ||
message: "SMS sent successfully.", | ||
}); | ||
} catch (error) { | ||
res.status(500).json({ | ||
status: "unsuccessful", | ||
status_code: 500, | ||
message: "Failed to send SMS. Please try again later.", | ||
}); | ||
} | ||
}; |
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
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,4 +1,5 @@ | ||
// silence is golden | ||
export * from "./AuthController"; | ||
export * from "./UserController"; | ||
export * from "./HelpController"; | ||
export * from "./HelpController"; | ||
export * from "./NotificationController"; |
Oops, something went wrong.