Skip to content

Commit

Permalink
Implement default contacts back into NPWD (#1116)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gittified authored Jan 13, 2024
1 parent 7134039 commit e4ee9b0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
9 changes: 8 additions & 1 deletion apps/game/server/contacts/contacts.database.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { Contact, PreDBContact } from '@typings/contact';
import { ResultSetHeader } from 'mysql2';
import { DbInterface } from '@npwd/database';
import { config } from '@npwd/config/server';

export class _ContactsDB {
private readonly defaultContacts: Contact[] = config.defaultContacts.map((contact) => ({
id: `${contact.display}:${contact.number}`,
...contact,
}));

async fetchAllContacts(identifier: string): Promise<Contact[]> {
const query = 'SELECT * FROM npwd_phone_contacts WHERE identifier = ? ORDER BY display ASC';
const [results] = await DbInterface._rawExec(query, [identifier]);
return <Contact[]>results;

return this.defaultContacts.concat(<Contact[]>results);
}

async addContact(
Expand Down
1 change: 0 additions & 1 deletion typings/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ interface VoiceMessageConfig {
}

export interface DefaultContact {
id: number;
display: string;
number: string;
avatar?: string;
Expand Down
2 changes: 1 addition & 1 deletion typings/contact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface PreDBContact {
}

export interface Contact extends PreDBContact {
id: number;
id: number | string;
}

export interface ContactPay {
Expand Down

0 comments on commit e4ee9b0

Please sign in to comment.