Skip to content
This repository has been archived by the owner on Nov 21, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Enkhtuvshin0513 authored and batamar committed Dec 16, 2019
1 parent 411c57b commit fdef0db
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/data/schema/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const types = `
position: String
location: String
description: String
operatorPhone: String
}
input UserLinks {
Expand Down Expand Up @@ -35,6 +36,7 @@ export const types = `
position: String
location: String
description: String
operatorPhone: String
}
type UserLinksType {
Expand Down
2 changes: 2 additions & 0 deletions src/db/models/definitions/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface IDetail {
position?: string;
location?: string;
description?: string;
operatorPhone?: string;
}

export interface IDetailDocument extends IDetail, Document {}
Expand Down Expand Up @@ -76,6 +77,7 @@ const detailSchema = new Schema(
position: field({ type: String, label: 'Position' }),
location: field({ type: String, optional: true, label: 'Location' }),
description: field({ type: String, optional: true, label: 'Description' }),
operatorPhone: field({ type: String, optional: true, label: 'Company phone' }),
},
{ _id: false },
);
Expand Down
12 changes: 8 additions & 4 deletions src/middlewares/integrationsApiMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConversationMessages, Conversations, Customers, Integrations } from '../db/models';
import { ConversationMessages, Conversations, Customers, Integrations, Users } from '../db/models';
import { CONVERSATION_STATUSES } from '../db/models/definitions/constants';
import { graphqlPubsub } from '../pubsub';

Expand Down Expand Up @@ -48,14 +48,18 @@ const integrationsApiMiddleware = async (req, res) => {
}

if (action === 'create-or-update-conversation') {
if (doc.conversationId) {
const { conversationId, content } = doc;
const { conversationId, content, owner } = doc;
const user = await Users.findOne({ 'details.operatorPhone': owner });
const assignedUserId = user ? user._id : '';

await Conversations.updateConversation(conversationId, { content });
if (conversationId) {
await Conversations.updateConversation(conversationId, { content, assignedUserId });

return res.json({ _id: conversationId });
}

doc.assignedUserId = assignedUserId;

const conversation = await Conversations.createConversation(doc);

return res.json({ _id: conversation._id });
Expand Down

0 comments on commit fdef0db

Please sign in to comment.