Skip to content
This repository was archived by the owner on Mar 9, 2021. It is now read-only.

Commit e7aa4a0

Browse files
committed
Add basic mongoose models, queries and mutations
1 parent 18f9600 commit e7aa4a0

File tree

10 files changed

+302
-1598
lines changed

10 files changed

+302
-1598
lines changed

Procfile renamed to Procfile

File renamed without changes.

index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1+
require('dotenv').config()
12
const { ApolloServer } = require('apollo-server')
3+
const mongoose = require('mongoose')
24

3-
const typeDefs = require('./typedefs')
5+
const typeDefs = require('./schema.gql')
46
const resolvers = require('./resolvers')
57

68
const server = new ApolloServer({
79
typeDefs,
810
resolvers
911
})
1012

11-
server.listen().then(({ url }) => {
12-
console.log(`🎉Server listening at ${url} !`)
13+
mongoose.connect(process.env.DB_URL, {
14+
useNewUrlParser: true
15+
}).then(() => {
16+
server.listen().then(({ url }) => {
17+
console.log(`🎉Server listening at ${url} !`)
18+
})
19+
},
20+
err => {
21+
console.log('failed to connect to the database')
22+
console.log(err)
1323
})

models/User.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const mongoose = require('mongoose')
2+
const { Schema } = mongoose
3+
4+
const UserSchema = new Schema({
5+
username: {
6+
type: String,
7+
required: true
8+
},
9+
email: {
10+
type: String,
11+
required: true
12+
},
13+
password: {
14+
type: String,
15+
required: true,
16+
minlength: 10
17+
},
18+
mobile: Number,
19+
bio: {
20+
type: String,
21+
maxlength: 1000
22+
},
23+
working: Boolean,
24+
forhire: Boolean,
25+
links: {
26+
facebook: String,
27+
twitter: String,
28+
linkedin: String,
29+
angellist: String,
30+
stackoverflow: String,
31+
codepen: String,
32+
github: String,
33+
behance: String,
34+
discord: String
35+
},
36+
techFamiliarWith: [String],
37+
techInterestedIn: [String],
38+
projects: [Schema.Types.ObjectId],
39+
hits: Number
40+
})
41+
42+
const User = mongoose.model('User', UserSchema)
43+
44+
module.exports = User

models/UserProject.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const mongoose = require('mongoose')
2+
const { Schema } = mongoose
3+
4+
const UserProjectSchema = new Schema({
5+
name: {
6+
type: String,
7+
required: true,
8+
minlength: 5,
9+
maxlength: 100
10+
},
11+
desc: {
12+
type: String,
13+
required: true,
14+
minlength: 100,
15+
maxlength: 1000
16+
},
17+
thumbnailUrl: String,
18+
creators: {
19+
type: [Schema.Types.ObjectId],
20+
required: true
21+
},
22+
link: {
23+
type: String,
24+
required: true
25+
},
26+
hits: Number
27+
})
28+
29+
module.exports = UserProjectSchema

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy