fix(server/contacts): Use old response structure for time being

This commit is contained in:
Taso committed 2021-04-19 14:14:25 -04:00
1 parent 4687635988
commit 048753f6d2
1 file changed
+25 -35
+25 -35
View File
@@ -10,6 +10,7 @@ class _ContactService {
constructor() { constructor() {
this.contactsDB = ContactsDB; this.contactsDB = ContactsDB;
contactsLogger.debug('Contacts service started');
} }
private responseBuilder(src: number, { data, action, error }: ContactServerResp): void { private responseBuilder(src: number, { data, action, error }: ContactServerResp): void {
@@ -27,17 +28,18 @@ class _ContactService {
const identifier = PlayerService.getIdentifier(src); const identifier = PlayerService.getIdentifier(src);
try { try {
await this.contactsDB.updateContact(contact, identifier); await this.contactsDB.updateContact(contact, identifier);
this.responseBuilder(src, {
action: ContactEvents.UPDATE_CONTACT, emitNet(ContactEvents.UPDATE_CONTACT_SUCCESS, src);
emitNet(ContactEvents.ACTION_RESULT, src, {
message: 'CONTACT_UPDATE_SUCCESS',
type: 'success',
}); });
} catch (e) { } catch (e) {
contactsLogger.error(`Error in handleUpdateContact (${identifier}), ${e.message}`); contactsLogger.error(`Error in handleUpdateContact (${identifier}), ${e.message}`);
this.responseBuilder(src, { emitNet(ContactEvents.ACTION_RESULT, src, {
action: ContactEvents.UPDATE_CONTACT, message: 'CONTACT_UPDATE_FAILED',
error: { type: 'error',
errorCode: ErrorStringKeys.UPDATE_FAILED,
message: `Failed to update contact ${contact.id}`,
},
}); });
} }
} }
@@ -45,16 +47,15 @@ class _ContactService {
const identifier = PlayerService.getIdentifier(src); const identifier = PlayerService.getIdentifier(src);
try { try {
await this.contactsDB.deleteContact(contactId, identifier); await this.contactsDB.deleteContact(contactId, identifier);
this.responseBuilder(src, { emitNet(ContactEvents.DELETE_CONTACT_SUCCESS, src);
action: ContactEvents.DELETE_CONTACT, emitNet(ContactEvents.ACTION_RESULT, src, {
message: 'CONTACT_DELETE_SUCCESS',
type: 'success',
}); });
} catch (e) { } catch (e) {
this.responseBuilder(src, { emitNet(ContactEvents.ACTION_RESULT, src, {
action: ContactEvents.DELETE_CONTACT, message: 'CONTACT_DELETE_FAILED',
error: { type: 'error',
errorCode: ErrorStringKeys.DELETE_FAILED,
message: `Failed to delete contactId ${contactId}`,
},
}); });
contactsLogger.error(`Error in handleDeleteContact (${identifier}), ${e.message}`); contactsLogger.error(`Error in handleDeleteContact (${identifier}), ${e.message}`);
} }
@@ -64,17 +65,16 @@ class _ContactService {
try { try {
await this.contactsDB.addContact(identifier, contact); await this.contactsDB.addContact(identifier, contact);
this.responseBuilder(src, { emitNet(ContactEvents.ADD_CONTACT_SUCCESS, src);
action: ContactEvents.ADD_CONTACT, emitNet(ContactEvents.ACTION_RESULT, src, {
message: 'CONTACT_ADD_SUCCESS',
type: 'success',
}); });
} catch (e) { } catch (e) {
contactsLogger.error(`Error in handleAddContact, ${e.message}`); contactsLogger.error(`Error in handleAddContact, ${e.message}`);
this.responseBuilder(src, { emitNet(ContactEvents.ACTION_RESULT, src, {
action: ContactEvents.ADD_CONTACT, message: 'CONTACT_ADD_FAILED',
error: { type: 'error',
errorCode: ErrorStringKeys.ADD_FAILED,
message: 'Unable to add contacts',
},
}); });
} }
} }
@@ -84,18 +84,8 @@ class _ContactService {
try { try {
const contacts = await this.contactsDB.fetchAllContacts(identifier, limit); const contacts = await this.contactsDB.fetchAllContacts(identifier, limit);
this.responseBuilder(src, { emitNet(ContactEvents.SEND_CONTACTS, src, contacts);
data: contacts,
action: ContactEvents.SEND_CONTACTS,
});
} catch (e) { } catch (e) {
this.responseBuilder(src, {
action: ContactEvents.SEND_CONTACTS,
error: {
errorCode: ErrorStringKeys.SERVER_ERROR,
message: 'Unable to fetch contacts',
},
});
contactsLogger.error(`Error in handleFetchContact (${identifier}), ${e.message}`); contactsLogger.error(`Error in handleFetchContact (${identifier}), ${e.message}`);
} }
} }