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

Commit 0fcc0df

Browse files
munkhjin0223batamar
authored andcommitted
Improvement activity log (#359)
Improved activity log
1 parent c62f3e7 commit 0fcc0df

File tree

7 files changed

+123
-14
lines changed

7 files changed

+123
-14
lines changed

activityLogs.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Document, Schema } from 'mongoose';
22
import { field } from '../utils';
3-
import { ACTIVITY_ACTIONS, ACTIVITY_PERFORMER_TYPES, ACTIVITY_TYPES, COC_CONTENT_TYPES } from './constants';
3+
import { ACTIVITY_ACTIONS, ACTIVITY_CONTENT_TYPES, ACTIVITY_PERFORMER_TYPES, ACTIVITY_TYPES } from './constants';
44

55
export interface IActionPerformer {
66
type: string;
@@ -22,23 +22,30 @@ interface IActivityDocument extends IActivity, Document {
2222
id?: string;
2323
}
2424

25-
export interface ICoc {
25+
export interface IContentType {
2626
id: string;
2727
type: string;
2828
}
2929

30-
interface ICocDocument extends ICoc, Document {
30+
interface IContentTypeDocument extends IContentType, Document {
3131
id: string;
3232
}
3333

3434
export interface IActivityLogDocument extends Document {
3535
_id: string;
3636
activity: IActivityDocument;
3737
performedBy?: IActionPerformerDocument;
38-
coc: ICocDocument;
38+
contentType: IContentTypeDocument;
3939
createdAt: Date;
4040
}
4141

42+
export interface IActivityLog {
43+
contentType: string;
44+
contentId: string;
45+
activityType: string;
46+
limit: number;
47+
}
48+
4249
// Mongoose schemas ===========
4350

4451
/* Performer of the action:
@@ -105,15 +112,15 @@ const activitySchema = new Schema(
105112

106113
/* the customer that is related to a given ActivityLog
107114
can be both Company or Customer documents */
108-
const cocSchema = new Schema(
115+
const contentTypeSchema = new Schema(
109116
{
110117
id: field({
111118
type: String,
112119
required: true,
113120
}),
114121
type: field({
115122
type: String,
116-
enum: COC_CONTENT_TYPES.ALL,
123+
enum: ACTIVITY_CONTENT_TYPES.ALL,
117124
required: true,
118125
}),
119126
},
@@ -124,7 +131,9 @@ export const activityLogSchema = new Schema({
124131
_id: field({ pkey: true }),
125132
activity: { type: activitySchema },
126133
performedBy: { type: actionPerformerSchema, optional: true },
127-
coc: { type: cocSchema },
134+
contentType: { type: contentTypeSchema },
135+
// TODO: remove
136+
coc: { type: contentTypeSchema, optional: true },
128137

129138
createdAt: field({
130139
type: Date,

companies.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
COMPANY_INDUSTRY_TYPES,
66
COMPANY_LEAD_STATUS_TYPES,
77
COMPANY_LIFECYCLE_STATE_TYPES,
8+
STATUSES,
89
} from './constants';
910

1011
import { field } from '../utils';
@@ -37,7 +38,9 @@ export interface ICompany {
3738
primaryPhone?: string;
3839
phones?: string[];
3940

41+
mergedIds?: string[];
4042
leadStatus?: string;
43+
status?: string;
4144
lifecycleState?: string;
4245
businessType?: string;
4346
description?: string;
@@ -52,6 +55,7 @@ export interface ICompany {
5255
export interface ICompanyDocument extends ICompany, Document {
5356
_id: string;
5457
links?: ILinkDocument;
58+
status?: string;
5559
createdAt: Date;
5660
modifiedAt: Date;
5761
}
@@ -135,6 +139,14 @@ export const companySchema = new Schema({
135139
label: 'Lead Status',
136140
}),
137141

142+
status: field({
143+
type: String,
144+
enum: STATUSES.ALL,
145+
default: STATUSES.ACTIVE,
146+
optional: true,
147+
label: 'Status',
148+
}),
149+
138150
lifecycleState: field({
139151
type: String,
140152
enum: COMPANY_LIFECYCLE_STATE_TYPES,
@@ -163,6 +175,9 @@ export const companySchema = new Schema({
163175
optional: true,
164176
}),
165177

178+
// Merged company ids
179+
mergedIds: field({ type: [String], optional: true }),
180+
166181
customFieldsData: field({
167182
type: Object,
168183
}),

constants.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export const FIELD_CONTENT_TYPES = {
163163
ALL: ['form', 'customer', 'company'],
164164
};
165165

166-
export const COC_CONTENT_TYPES = {
166+
export const ACTIVITY_CONTENT_TYPES = {
167167
CUSTOMER: 'customer',
168168
COMPANY: 'company',
169169
USER: 'user',
@@ -198,9 +198,10 @@ export const ACTIVITY_ACTIONS = {
198198
CREATE: 'create',
199199
UPDATE: 'update',
200200
DELETE: 'delete',
201+
MERGE: 'merge',
201202
SEND: 'send',
202203

203-
ALL: ['create', 'update', 'delete', 'send'],
204+
ALL: ['create', 'update', 'delete', 'merge', 'send'],
204205
};
205206

206207
export const ACTIVITY_PERFORMER_TYPES = {
@@ -389,3 +390,15 @@ export const PROBABILITY = {
389390
LOST: 'Lost',
390391
ALL: ['10%', '20%', '30%', '40%', '50%', '60%', '70%', '80%', '90%', 'Won', 'Lost'],
391392
};
393+
394+
export const STATUSES = {
395+
ACTIVE: 'Active',
396+
DELETED: 'Deleted',
397+
ALL: ['Active', 'Deleted'],
398+
};
399+
400+
export const EMAIL_TYPES = {
401+
GMAIL: 'gmail',
402+
OTHER: 'other',
403+
ALL: ['gmail', 'other'],
404+
};

customers.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Document, Schema } from 'mongoose';
22

3-
import { CUSTOMER_LEAD_STATUS_TYPES, CUSTOMER_LIFECYCLE_STATE_TYPES } from './constants';
3+
import { CUSTOMER_LEAD_STATUS_TYPES, CUSTOMER_LIFECYCLE_STATE_TYPES, STATUSES } from './constants';
44

55
import { field } from '../utils';
66

@@ -87,6 +87,8 @@ export interface ICustomer {
8787
integrationId?: string;
8888
tagIds?: string[];
8989
companyIds?: string[];
90+
mergedIds?: string[];
91+
status?: string;
9092
customFieldsData?: any;
9193
messengerData?: IMessengerData;
9294
twitterData?: ITwitterData;
@@ -104,6 +106,7 @@ export interface ICustomerDocument extends ICustomer, Document {
104106
location?: ILocationDocument;
105107
links?: ILinkDocument;
106108
visitorContactInfo?: IVisitorContactDocument;
109+
status?: string;
107110
createdAt: Date;
108111
modifiedAt: Date;
109112
}
@@ -230,6 +233,14 @@ export const customerSchema = new Schema({
230233
label: 'Lead Status',
231234
}),
232235

236+
status: field({
237+
type: String,
238+
enum: STATUSES.ALL,
239+
default: STATUSES.ACTIVE,
240+
optional: true,
241+
label: 'Status',
242+
}),
243+
233244
lifecycleState: field({
234245
type: String,
235246
enum: CUSTOMER_LIFECYCLE_STATE_TYPES,
@@ -252,6 +263,9 @@ export const customerSchema = new Schema({
252263
tagIds: field({ type: [String], optional: true }),
253264
companyIds: field({ type: [String], optional: true }),
254265

266+
// Merged customer ids
267+
mergedIds: field({ type: [String], optional: true }),
268+
255269
customFieldsData: field({ type: Object, optional: true }),
256270
messengerData: field({ type: messengerSchema, optional: true }),
257271
twitterData: field({ type: twitterSchema, optional: true }),

emailDeliveries.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { Document, Schema } from 'mongoose';
2+
import { field } from '../utils';
3+
import { EMAIL_TYPES } from './constants';
4+
5+
interface IAttachmentParams {
6+
data: string;
7+
filename: string;
8+
size: number;
9+
mimeType: string;
10+
}
11+
12+
export interface IEmailDeliveries {
13+
cocType: string;
14+
cocId: string;
15+
subject: string;
16+
body: string;
17+
toEmails: string;
18+
cc?: string;
19+
bcc?: string;
20+
attachments?: IAttachmentParams[];
21+
fromEmail?: string;
22+
type?: string;
23+
userId: string;
24+
}
25+
26+
export interface IEmailDeliveriesDocument extends IEmailDeliveries, Document {
27+
id: string;
28+
}
29+
30+
// Mongoose schemas ===========
31+
32+
const attachmentSchema = new Schema(
33+
{
34+
data: field({ type: String }),
35+
filename: field({ type: String }),
36+
size: field({ type: Number }),
37+
mimeType: field({ type: String }),
38+
},
39+
{ _id: false },
40+
);
41+
42+
export const emailDeliverySchema = new Schema({
43+
_id: field({ pkey: true }),
44+
cocType: field({ type: String }),
45+
cocId: field({ type: String }),
46+
subject: field({ type: String, optional: true }),
47+
body: field({ type: String }),
48+
toEmails: field({ type: String }),
49+
cc: field({ type: String, optional: true }),
50+
bcc: field({ type: String, optional: true }),
51+
attachments: field({ type: [attachmentSchema] }),
52+
fromEmail: field({ type: String }),
53+
userId: field({ type: String }),
54+
55+
type: { type: String, enum: EMAIL_TYPES.ALL, default: EMAIL_TYPES.GMAIL },
56+
57+
createdAt: field({ type: Date, default: Date.now }),
58+
});

internalNotes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Document, Schema } from 'mongoose';
22
import { field } from '../utils';
3-
import { COC_CONTENT_TYPES } from './constants';
3+
import { ACTIVITY_CONTENT_TYPES } from './constants';
44

55
export interface IInternalNote {
66
contentType: string;
@@ -20,7 +20,7 @@ export const internalNoteSchema = new Schema({
2020
_id: field({ pkey: true }),
2121
contentType: field({
2222
type: String,
23-
enum: COC_CONTENT_TYPES.ALL,
23+
enum: ACTIVITY_CONTENT_TYPES.ALL,
2424
}),
2525
contentTypeId: field({ type: String }),
2626
content: field({

segments.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Document, Schema } from 'mongoose';
22
import { field } from '../utils';
3-
import { COC_CONTENT_TYPES } from './constants';
3+
import { ACTIVITY_CONTENT_TYPES } from './constants';
44

55
export interface ICondition {
66
field: string;
@@ -51,7 +51,7 @@ export const segmentSchema = new Schema({
5151
_id: field({ pkey: true }),
5252
contentType: field({
5353
type: String,
54-
enum: COC_CONTENT_TYPES.ALL,
54+
enum: ACTIVITY_CONTENT_TYPES.ALL,
5555
}),
5656
name: field({ type: String }),
5757
description: field({ type: String, optional: true }),

0 commit comments

Comments
 (0)