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

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
BatAmar Battulga committed Dec 15, 2019
2 parents e7e1606 + 467d074 commit 75c0848
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 27 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"nodemailer": "^4.0.1",
"q": "^1.5.1",
"snyk": "^1.239.5",
"strip": "^3.0.0",
"underscore": "^1.8.3",
"validator": "^10.9.0"
},
Expand Down
14 changes: 11 additions & 3 deletions src/data/resolvers/mutations/messenger.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as strip from 'strip';

import { Brands, Companies, Conversations, Customers, Integrations, Messages } from '../../../db/models';

import { IBrowserInfo, IVisitorContactInfoParams } from '../../../db/models/Customers';
Expand All @@ -16,14 +18,15 @@ export default {
brandCode: string;
email?: string;
phone?: string;
code?: string;
isUser?: boolean;
companyData?: any;
data?: any;
cachedCustomerId?: string;
deviceToken?: string;
},
) {
const { brandCode, email, phone, isUser, companyData, data, cachedCustomerId, deviceToken } = args;
const { brandCode, email, phone, code, isUser, companyData, data, cachedCustomerId, deviceToken } = args;

const customData = data;

Expand All @@ -41,6 +44,7 @@ export default {
cachedCustomerId,
email,
phone,
code,
});

if (customer) {
Expand All @@ -50,6 +54,7 @@ export default {
doc: {
email,
phone,
code,
isUser,
deviceToken,
},
Expand All @@ -63,6 +68,7 @@ export default {
integrationId: integration._id,
email,
phone,
code,
isUser,
deviceToken,
},
Expand Down Expand Up @@ -108,12 +114,14 @@ export default {
) {
const { integrationId, customerId, conversationId, message, attachments } = args;

const conversationContent = strip(message || '').substring(0, 100);

// get or create conversation
const conversation = await Conversations.getOrCreateConversation({
conversationId,
integrationId,
customerId,
content: message,
content: conversationContent,
});

// create message
Expand All @@ -132,7 +140,7 @@ export default {
status: Conversations.getConversationStatuses().OPEN,

// setting conversation's content to last message
content: message,
content: conversationContent,

// Mark as unread
readUserIds: [],
Expand Down
1 change: 1 addition & 0 deletions src/data/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export const mutations = `
brandCode: String!
email: String
phone: String
code: String
isUser: Boolean
companyData: JSON
Expand Down
1 change: 1 addition & 0 deletions src/db/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export function customerFactory(params: ICustomerParams = {}) {
},
urlVisits: params.urlVisits,
deviceTokens: params.deviceToken || [],
code: faker.random.word(),
});

return customer.save();
Expand Down
32 changes: 22 additions & 10 deletions src/db/models/Customers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Integrations from './Integrations';
interface IGetCustomerParams {
email?: string;
phone?: string;
code?: string;
cachedCustomerId?: string;
}

Expand All @@ -14,6 +15,7 @@ interface ICreateCustomerParams {
email?: string;
hasValidEmail?: boolean;
phone?: string;
code?: string;
isUser?: boolean;
firstName?: string;
lastName?: string;
Expand All @@ -27,6 +29,7 @@ export interface IUpdateMessengerCustomerParams {
doc: {
email?: string;
phone?: string;
code?: string;
isUser?: boolean;
deviceToken?: string;
};
Expand Down Expand Up @@ -131,12 +134,15 @@ export const loadClass = () => {

if (!nullValues.includes(customer.primaryEmail || '')) {
score += 15;
searchText = searchText.concat(' ', customer.primaryEmail);
}

if (!nullValues.includes(customer.primaryPhone || '')) {
score += 10;
searchText = searchText.concat(' ', customer.primaryPhone);
}

if (!nullValues.includes(customer.code || '')) {
score += 10;
searchText = searchText.concat(' ', customer.code);
}

if (customer.visitorContactInfo != null) {
Expand Down Expand Up @@ -164,26 +170,32 @@ export const loadClass = () => {
/*
* Get customer
*/
public static getCustomer(params: IGetCustomerParams) {
const { email, phone, cachedCustomerId } = params;
public static async getCustomer(params: IGetCustomerParams) {
const { email, phone, code, cachedCustomerId } = params;

let customer: ICustomerDocument;

if (email) {
return Customers.findOne({
customer = await Customers.findOne({
$or: [{ emails: { $in: [email] } }, { primaryEmail: email }],
});
}

if (phone) {
return Customers.findOne({
if (!customer && phone) {
customer = await Customers.findOne({
$or: [{ phones: { $in: [phone] } }, { primaryPhone: phone }],
});
}

if (cachedCustomerId) {
return Customers.findOne({ _id: cachedCustomerId });
if (!customer && code) {
customer = await Customers.findOne({ code });
}

if (!customer && cachedCustomerId) {
customer = await Customers.findOne({ _id: cachedCustomerId });
}

return null;
return customer;
}

/*
Expand Down
9 changes: 8 additions & 1 deletion src/db/models/definitions/boards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface IItemCommonFields {
assignedUserIds?: string[];
watchedUserIds?: string[];
notifiedUserIds?: string[];
labelIds?: string[];
attachments?: any[];
stageId?: string;
initialStageId?: string;
Expand All @@ -28,6 +29,7 @@ export interface IItemCommonFields {
createdAt?: Date;
order?: number;
searchText?: string;
priority?: string;
}

export interface IBoard extends ICommonFields {
Expand All @@ -45,12 +47,13 @@ export interface IPipeline extends ICommonFields {
memberIds?: string[];
bgColor?: string;
watchedUserIds?: string[];
// growth hack
startDate?: Date;
endDate?: Date;
metric?: string;
hackScoringType?: string;
templateId?: string;
isCheckUser?: boolean;
excludeCheckUserIds?: string[];
}

export interface IPipelineDocument extends IPipeline, Document {
Expand Down Expand Up @@ -116,6 +119,7 @@ export const commonItemFieldsSchema = {
description: field({ type: String, optional: true }),
assignedUserIds: field({ type: [String] }),
watchedUserIds: field({ type: [String] }),
labelIds: field({ type: [String] }),
attachments: field({ type: [attachmentSchema] }),
stageId: field({ type: String }),
initialStageId: field({ type: String, optional: true }),
Expand All @@ -125,6 +129,7 @@ export const commonItemFieldsSchema = {
}),
modifiedBy: field({ type: String }),
searchText: field({ type: String, optional: true, index: true }),
priority: field({ type: String, optional: true }),
};

export const boardSchema = schemaWrapper(
Expand Down Expand Up @@ -156,6 +161,8 @@ export const pipelineSchema = new Schema({
enum: HACK_SCORING_TYPES.ALL,
}),
templateId: field({ type: String, optional: true }),
isCheckUser: field({ type: Boolean, optional: true }),
excludeCheckUserIds: field({ type: [String], optional: true }),
...commonFieldsSchema,
});

Expand Down
50 changes: 50 additions & 0 deletions src/db/models/definitions/checklists.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Document, Schema } from 'mongoose';
import { ACTIVITY_CONTENT_TYPES } from './constants';
import { field } from './utils';

export interface IChecklist {
contentType: string;
contentTypeId: string;
title: string;
}

export interface IChecklistDocument extends IChecklist, Document {
_id: string;
createdUserId: string;
createdDate: Date;
}

export interface IChecklistItem {
checklistId: string;
content: string;
isChecked: boolean;
}

export interface IChecklistItemDocument extends IChecklistItem, Document {
_id: string;
createdUserId: string;
createdDate: Date;
}

// Mongoose schemas =======================

export const checklistSchema = new Schema({
_id: field({ pkey: true }),
contentType: field({
type: String,
enum: ACTIVITY_CONTENT_TYPES.ALL,
}),
contentTypeId: field({ type: String }),
title: field({ type: String }),
createdUserId: field({ type: String }),
createdDate: field({ type: Date }),
});

export const checklistItemSchema = new Schema({
_id: field({ pkey: true }),
checklistId: field({ type: String }),
content: field({ type: String }),
isChecked: field({ type: Boolean }),
createdUserId: field({ type: String }),
createdDate: field({ type: Date }),
});
39 changes: 38 additions & 1 deletion src/db/models/definitions/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,44 @@ export const KIND_CHOICES = {
FACEBOOK_POST: 'facebook-post',
GMAIL: 'gmail',
NYLAS_GMAIL: 'nylas-gmail',
NYLAS_IMAP: 'nylas-imap',
NYLAS_OFFICE365: 'nylas-office365',
NYLAS_OUTLOOK: 'nylas-outlook',
NYLAS_YAHOO: 'nylas-yahoo',
CALLPRO: 'callpro',
TWITTER_DM: 'twitter-dm',
CHATFUEL: 'chatfuel',
ALL: ['messenger', 'lead', 'facebook-messenger', 'facebook-post', 'gmail', 'callpro', 'chatfuel', 'nylas-gmail'],
ALL: [
'messenger',
'lead',
'facebook-messenger',
'facebook-post',
'gmail',
'callpro',
'chatfuel',
'nylas-gmail',
'nylas-imap',
'nylas-office365',
'nylas-outlook',
'nylas-yahoo',
'twitter-dm',
],
};

export const INTEGRATION_NAMES_MAP = {
messenger: 'Web messenger',
lead: 'Lead',
'facebook-messenger': 'Facebook messenger',
'facebook-post': 'Facebook post',
gmail: 'Gmail',
callpro: 'Call pro',
chatfuel: 'Chatfuel',
'nylas-gmail': 'Gmail',
'nylas-imap': 'Imap',
'nylas-office365': 'Office 365',
'nylas-outlook': 'Outook',
'nylas-yahoo': 'Yahoo',
'twitter-dm': 'Twitter dm',
};

// messenger data availability constants
Expand Down Expand Up @@ -94,6 +129,7 @@ export const ACTIVITY_TYPES = {
CUSTOMER: 'customer',
COMPANY: 'company',
INTERNAL_NOTE: 'internal_note',
CHECKLIST: 'checklist',
CONVERSATION: 'conversation',
SEGMENT: 'segment',
DEAL: 'deal',
Expand All @@ -107,6 +143,7 @@ export const ACTIVITY_TYPES = {
'customer',
'company',
'internal_note',
'checklist',
'conversation',
'segment',
'deal',
Expand Down
2 changes: 2 additions & 0 deletions src/db/models/definitions/customers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export interface ICustomer {
visitorContactInfo?: IVisitorContact;
urlVisits?: any;
deviceTokens?: string[];
code?: string;
}

export interface ICustomerDocument extends ICustomer, Document {
Expand Down Expand Up @@ -230,5 +231,6 @@ export const customerSchema = schemaWrapper(

deviceTokens: field({ type: [String], default: [] }),
searchText: field({ type: String, optional: true, index: true }),
code: field({ type: String, label: 'Code', optional: true }),
}),
);
2 changes: 0 additions & 2 deletions src/db/models/definitions/growthHacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export interface IGrowthHack extends IItemCommonFields {
votedUserIds?: string[];

hackStages?: string;
priority?: string;
reach?: number;
impact?: number;
confidence?: number;
Expand All @@ -25,7 +24,6 @@ export const growthHackSchema = new Schema({
votedUserIds: field({ type: [String], optional: true }),

hackStages: field({ type: [String], optional: true }),
priority: field({ type: String, optional: true }),
reach: field({ type: Number, default: 0, optional: true }),
impact: field({ type: Number, default: 0, optional: true }),
confidence: field({ type: Number, default: 0, optional: true }),
Expand Down
4 changes: 4 additions & 0 deletions src/db/models/definitions/integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,14 @@ export interface IIntegration {
leadData?: ILeadData;
messengerData?: IMessengerData;
uiOptions?: IUiOptions;
isActive?: boolean;
}

export interface IIntegrationDocument extends IIntegration, Document {
_id: string;
createdUserId: string;
// TODO remove
formData?: ILeadData;
leadData?: ILeadDataDocument;
messengerData?: IMessengerDataDocument;
uiOptions?: IUiOptionsDocument;
Expand Down Expand Up @@ -273,4 +276,5 @@ export const integrationSchema = new Schema({
formData: field({ type: leadDataSchema }),
messengerData: field({ type: messengerDataSchema }),
uiOptions: field({ type: uiOptionsSchema }),
isActive: field({ type: Boolean, optional: true, default: true }),
});
Loading

0 comments on commit 75c0848

Please sign in to comment.