-
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.
- Loading branch information
Showing
26 changed files
with
555 additions
and
233 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
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,64 @@ | ||
// src/controllers/UserController.ts | ||
import { Request, Response } from "express"; | ||
import { HelpService } from "../services"; | ||
import { HttpError } from "../middleware"; | ||
|
||
class HelpController { | ||
private helpService: HelpService; | ||
|
||
constructor() { | ||
this.helpService = new HelpService(); | ||
} | ||
|
||
async createTopic(req: Request, res:Response):Promise<void> { | ||
try { | ||
const topic = await this.helpService.create(req); | ||
res.status(201).json({ | ||
success: true, | ||
message: 'Topic Created Successfully', | ||
data: { | ||
article_id: topic.id, | ||
content: topic.content, | ||
author: topic.author, | ||
title: topic.title, | ||
createdAt: topic.createdAt, | ||
updatedAt: topic.updatedAt | ||
}, | ||
status_code: 201 | ||
}); | ||
} catch (error) { | ||
if (error instanceof HttpError) { | ||
res.status(error.status).json({message: error.message}); | ||
} else { | ||
res.status(500).json({ message: error.message || "Internal Server Error" }); | ||
} | ||
} | ||
} | ||
|
||
async updateTopic(req: Request, res:Response):Promise<void> { | ||
try { | ||
const topic = await this.helpService.update(req); | ||
res.status(200).json({ | ||
success: true, | ||
message: 'Topic Updated Successfully', | ||
data: { | ||
article_id: topic.id, | ||
content: topic.content, | ||
author: topic.author, | ||
title: topic.title, | ||
createdAt: topic.createdAt, | ||
updatedAt: topic.updatedAt | ||
}, | ||
status_code: 200 | ||
}); | ||
} catch (error) { | ||
if (error instanceof HttpError) { | ||
res.status(error.status).json({message: error.message}); | ||
} else { | ||
res.status(500).json({ message: error.message || "Internal Server Error" }); | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default HelpController; |
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
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
Oops, something went wrong.