mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
refactor(server/calls): Calls singleton architecture
This commit is contained in:
1 parent
bb7d938b07
commit
bf95ccb06b
4 files changed
+173
-139
No files matched your search
@@ -2,22 +2,24 @@ import { CallHistoryItem } from '../../../typings/call';
|
||||
import { pool } from '../db';
|
||||
|
||||
export class CallsRepo {
|
||||
async saveCallDB(call: CallHistoryItem) {
|
||||
async saveCall(call: CallHistoryItem) {
|
||||
const query =
|
||||
'INSERT INTO npwd_calls (identifier, transmitter, receiver, start) VALUES (?, ?, ?, ?)';
|
||||
await pool.query(query, [call.identifier, call.transmitter, call.receiver, call.start]);
|
||||
}
|
||||
|
||||
async updateCallDB(call: CallHistoryItem, isAccepted: boolean, end: number) {
|
||||
async updateCall(call: CallHistoryItem, isAccepted: boolean, end: number) {
|
||||
const query = 'UPDATE npwd_calls SET is_accepted=?, end=? WHERE identifier = ?';
|
||||
await pool.query(query, [isAccepted, end, call.identifier]).catch(e =);
|
||||
await pool.query(query, [isAccepted, end, call.identifier]);
|
||||
}
|
||||
|
||||
async fetchCallsDB(phoneNumber: string): Promise<CallHistoryItem[]> {
|
||||
const query = 'SELECT * FROM npwd_calls WHERE receiver = ? OR transmitter = ? ORDER BY id DESC';
|
||||
const [result] = await pool.query(query, [phoneNumber, phoneNumber]);
|
||||
async fetchCalls(phoneNumber: string, limit = 50): Promise<CallHistoryItem[] | CallHistoryItem> {
|
||||
const query =
|
||||
'SELECT * FROM npwd_calls WHERE receiver = ? OR transmitter = ? ORDER BY id DESC LIMIT ?';
|
||||
const [result] = await pool.query(query, [phoneNumber, phoneNumber, limit]);
|
||||
|
||||
return <CallHistoryItem[]>result;
|
||||
}
|
||||
}
|
||||
|
||||
export default new CallsRepo()
|
||||
export default new CallsRepo();
|
||||
Reference in new issue
Block a user