JavaScript required
We’re sorry, but Coda doesn’t work properly without JavaScript enabled.
Skip to content
Gallery
AgencyHandy
AgencyHandy Handbook
Central issue and enhancment
UX
Onethread Handbook
Office Requirement and concerns
Check List
DevOps
KPI
Product Documentation
Notify on row update
Work
Untitled page
Interview
PC requirements
PM Task
More
Share
Explore
Planning
Intake form
const
mongoose
=
require
(
'mongoose'
)
;
const
optionsSchema
=
new
mongoose
.
Schema
(
{
value
:
String
,
label
:
String
,
}
)
;
const
customFieldSchema
=
new
mongoose
.
Schema
(
{
name
:
{
type
:
String
,
required
:
true
,
}
,
type
:
{
type
:
String
,
enum
:
[
'text'
,
'number'
,
'dropdown'
,
'multiSelect'
,
'singleSelect'
,
'currency'
,
'date'
,
]
,
required
:
true
,
}
,
}
,
{
timestamps
:
true
,
}
,
)
;
const
CustomField
=
mongoose
.
model
(
'CustomField'
,
customFieldSchema
)
;
const
formCustomFieldSchema
=
new
mongoose
.
Schema
(
{
name
:
{
type
:
String
,
required
:
true
,
}
,
customField
:
{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
ref
:
'CustomField'
,
required
:
true
,
}
,
form
:
{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
ref
:
'Form'
,
required
:
true
,
}
,
stringValue
:
{
type
:
String
,
default
:
undefined
,
}
,
numberValue
:
{
type
:
Number
,
default
:
undefined
,
}
,
dateValue
:
{
type
:
Date
,
default
:
undefined
,
}
,
arrayValue
:
{
type
:
[
optionsSchema
]
,
default
:
undefined
,
required
:
function
(
)
{
return
[
'dropdown'
,
'singleSelect'
,
'multiSelect'
]
.
includes
(
this
.
type
)
;
}
,
}
,
mode
:
{
type
:
String
,
enum
:
[
'create'
,
'edit'
]
,
}
,
createdBy
:
{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
ref
:
'Member'
,
required
:
true
,
}
,
}
,
{
timestamps
:
true
,
}
,
)
;
formCustomFieldSchema
.
index
(
{
customField
:
1
,
form
:
1
}
,
{
unique
:
true
}
)
;
const
FormCustomField
=
mongoose
.
model
(
'FormCustomField'
,
formCustomFieldSchema
,
)
;
module
.
exports
=
{
CustomField
,
FormCustomField
,
}
;
Let users create form
const
mongoose
=
require
(
'mongoose'
)
;
FormSchema
=
new
mongoose
.
Schema
(
{
name
:
{
type
:
String
,
required
:
true
,
trim
:
true
,
min
:
3
,
max
:
64
,
}
,
type
:
{
type
:
String
,
enum
:
[
'orderForm'
,
'intakeForm'
]
,
}
,
show
:
{
type
:
String
,
enum
:
[
'prePurchase'
,
'postPurchase'
]
,
required
:
true
,
}
,
createdBy
:
{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
ref
:
'Member'
,
required
:
true
,
}
,
company
:
{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
ref
:
'Company'
,
required
:
true
,
}
,
}
,
{
timestamps
:
true
}
,
)
;
FormSchema
.
index
(
{
company
:
1
}
)
;
const
FormSchema
=
mongoose
.
model
(
'FormSchema'
,
FormSchemaSchema
)
;
module
.
exports
=
{
Service
,
FormSchema
}
;
a form will have customFields.
reponses from orders will be saved in FormResponses
updated service schema
const
mongoose
=
require
(
'mongoose'
)
;
const
{
Schema
}
=
mongoose
;
const
ServiceSchema
=
new
mongoose
.
Schema
(
{
name
:
{
type
:
String
,
required
:
true
,
trim
:
true
,
min
:
3
,
max
:
64
,
}
,
slug
:
{
type
:
String
,
trim
:
true
,
required
:
true
,
unique
:
true
,
}
,
description
:
{
type
:
String
,
trim
:
true
,
min
:
3
,
}
,
duration
:
{
type
:
String
,
}
,
isPublished
:
{
type
:
Boolean
,
default
:
false
,
}
,
createdBy
:
{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
ref
:
'Member'
,
required
:
true
,
}
,
orderForm
:
{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
ref
:
'Form'
,
}
,
intakeForm
:
{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
ref
:
'Form'
,
}
,
company
:
{
type
:
mongoose
.
Schema
.
Types
.
ObjectId
,
ref
:
'Company'
,
required
:
true
,
}
,
}
,
{
timestamps
:
true
}
,
)
;
ServiceSchema
.
index
(
{
company
:
1
}
)
;
// ServiceSchema.index({ slug: 1 }, { name: 'service_slug' });
const
Service
=
mongoose
.
model
(
'Service'
,
ServiceSchema
)
;
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
Ctrl
P
) instead.