-
Notifications
You must be signed in to change notification settings - Fork 37
/
Message.js
49 lines (48 loc) · 1.08 KB
/
Message.js
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
// models/Message.js
import Cosmic from 'cosmicjs'
export default {
create: (config, params, callback) => {
const object = {
title: params.author + ': ' + params.message,
type_slug: config.bucket.type_slug,
metafields: [
{
title: 'Message',
key: 'message',
value: params.message,
type: 'textarea',
edit: 1
},
{
title: 'Author',
key: 'author',
value: params.author,
type: 'text',
edit: 1
}
],
options: {
slug_field: 0,
content_editor: 0,
add_metafields: 0,
metafields_title: 0,
metafields_key: 0
}
}
Cosmic.addObject(config, object, (err, res) => {
const new_object = res.object
const message = {
_id: new_object._id,
metafield: {
message: {
value: new_object.metafields[0].value
},
author: {
value: new_object.metafields[1].value
}
}
}
callback(message)
})
}
}