-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathendpoints.ts
More file actions
94 lines (92 loc) · 2.14 KB
/
endpoints.ts
File metadata and controls
94 lines (92 loc) · 2.14 KB
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
import { createCrud } from '@qelos/plugin-play'
import { collections, EventDoc } from './services/db';
import { ObjectId } from 'mongodb';
const events = collections.events;
createCrud<EventDoc>({
display: {
name: 'event'
},
verify: async (req) => {
return true;
},
readOne: (_id, { tenantPayload }) => events.findOne({ _id: new ObjectId(_id), tenant: tenantPayload.sub }),
createOne: async (body, { user, tenantPayload }) => {
const data: any = { ...body, user: user._id, tenant: tenantPayload.sub };
const res = await events.insertOne(data);
data._id = res.insertedId;
return data;
},
readMany: async (query, { tenantPayload }) => {
const dbQuery: any = { tenant: tenantPayload.sub };
if (query.tags) {
dbQuery.tags = query.tags
}
return events.find({ tenant: tenantPayload.sub }).toArray()
},
updateOne: async (_id, body: EventDoc, { user, tenantPayload }) => {
await events.updateOne({
_id: new ObjectId(_id),
user: user._id,
tenant: tenantPayload.sub
}, { $set: body })
return {
...body,
_id
};
},
deleteOne: async (_id, { user, tenantPayload }) => {
const item = await events.findOne({
_id: new ObjectId(_id),
user: user._id,
tenant: tenantPayload.sub
})
await events.deleteOne({
_id: new ObjectId(_id),
user: user._id,
tenant: tenantPayload.sub
});
return item
},
schema: {
title: {
type: String,
public: true
},
scheduledTo: {
type: Date,
public: true
},
description: {
type: String,
public: true
},
location: {
type: {
lat: Number,
lng: Number,
description: String
},
public: true
},
tags: {
type: [String],
public: true
}
},
screens: {
create: {
structure: `
<EditHeader>
Create the event here
</EditHeader>
<FormRowGroup>
<FormInput v-model="row.title" title="Title" />
<FormInput v-model="row.description" title="Description" />
</FormRowGroup>
`
},
edit: {},
list: {},
view: {}
}
})