This repository has been archived by the owner on Jan 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
engages.ts
130 lines (115 loc) · 3.16 KB
/
engages.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { Document, Schema } from 'mongoose';
import { IRule, ruleSchema } from './common';
import { MESSENGER_KINDS, METHODS, SENT_AS_CHOICES } from './constants';
import { field, schemaWrapper } from './utils';
export interface IScheduleDate {
type?: string;
month?: string | number;
day?: string | number;
time?: string;
}
interface IScheduleDateDocument extends IScheduleDate, Document {}
export interface IEmail {
attachments?: any;
subject?: string;
content?: string;
templateId?: string;
}
export interface IEmailDocument extends IEmail, Document {}
export interface IMessenger {
brandId?: string;
kind?: string;
sentAs?: string;
content?: string;
rules?: IRule[];
}
interface IMessengerDocument extends IMessenger, Document {}
export interface IEngageMessage {
kind?: string;
segmentIds?: string[];
brandIds?: string[];
tagIds?: string[];
customerIds?: string[];
title?: string;
fromUserId?: string;
method?: string;
isDraft?: boolean;
isLive?: boolean;
stopDate?: Date;
messengerReceivedCustomerIds?: string[];
email?: IEmail;
scheduleDate?: IScheduleDate;
messenger?: IMessenger;
}
export interface IEngageMessageDocument extends IEngageMessage, Document {
scheduleDate?: IScheduleDateDocument;
email?: IEmailDocument;
messenger?: IMessengerDocument;
_id: string;
}
// Mongoose schemas =======================
const scheduleDateSchema = new Schema(
{
type: field({ type: String, optional: true }),
month: field({ type: String, optional: true }),
day: field({ type: String, optional: true }),
time: field({ type: Date, optional: true }),
},
{ _id: false },
);
const emailSchema = new Schema(
{
attachments: field({ type: Object, optional: true }),
subject: field({ type: String }),
content: field({ type: String }),
templateId: field({ type: String, optional: true }),
},
{ _id: false },
);
const messengerSchema = new Schema(
{
brandId: field({ type: String }),
kind: field({
type: String,
enum: MESSENGER_KINDS.ALL,
}),
sentAs: field({
type: String,
enum: SENT_AS_CHOICES.ALL,
}),
content: field({ type: String }),
rules: field({ type: [ruleSchema] }),
},
{ _id: false },
);
export const engageMessageSchema = schemaWrapper(
new Schema({
_id: field({ pkey: true }),
kind: field({ type: String }),
segmentId: field({ type: String, optional: true }), // TODO Remove
segmentIds: field({
type: [String],
optional: true,
}),
brandIds: field({
type: [String],
optional: true,
}),
customerIds: field({ type: [String] }),
title: field({ type: String }),
fromUserId: field({ type: String }),
method: field({
type: String,
enum: METHODS.ALL,
}),
isDraft: field({ type: Boolean }),
isLive: field({ type: Boolean }),
stopDate: field({ type: Date }),
createdDate: field({ type: Date }),
tagIds: field({ type: [String], optional: true }),
messengerReceivedCustomerIds: field({ type: [String] }),
email: field({ type: emailSchema }),
scheduleDate: field({ type: scheduleDateSchema }),
messenger: field({ type: messengerSchema }),
}),
);