-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
79 lines (70 loc) · 1.63 KB
/
index.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
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
const express = require('express');
const bodyParser = require('body-parser');
const { graphiqlExpress, graphqlExpress } = require('apollo-server-express');
const { makeExecutableSchema } = require('graphql-tools');
const mongoose = require('mongoose');
const cors = require('cors');
const typeDefs = require('./schema');
const resolvers = require('./resolvers');
const schema = makeExecutableSchema({
typeDefs,
resolvers,
});
mongoose.connect('mongodb://localhost/deed');
const User = mongoose.model('User', {
userName: String,
firstName: String,
lastName: String,
password: String,
image: String,
email: String,
city: String,
groups: [String],
delegate: [String],
tasks: [String],
karmas: [{
karmaPoint: Number,
group: String,
image: String
}]
});
const Group = mongoose.model('Group', {
name: String,
type: String,
users: [String],
delegates: [String],
tasks: [String],
messages: [{
author: String,
text: String,
timeStamp: Number
}],
icon: String,
coverPhoto: String,
prizes: [{
image: String,
desc: String,
points: Number
}],
});
const Task = mongoose.model('Task', {
group: String,
title: String,
content: String,
status: String,
image: String,
points: Number,
userCompleted: String,
prove: {
image: String,
text: String
}
});
const PORT = 3000;
const app = express();
app.use(cors());
app.use(express.static('./client'));
app.use(bodyParser.json());
app.use('/graphql', bodyParser.json(), graphqlExpress({ schema, context: { User, Group, Task } }));
app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));
app.listen(PORT);