This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
services: | |
app: | |
container_name: docker_nodejsauth | |
restart: always | |
build: . | |
ports: | |
- 4001:4001 | |
links: | |
- mongo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
services: | |
app: | |
container_name: docker_nodejsauth | |
restart: always | |
build: . | |
ports: | |
- 4001:4001 | |
links: | |
- mongo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
services: | |
app: | |
container_name: docker_nodejsauth | |
restart: always | |
build: . | |
ports: | |
- 4001:4001 | |
links: | |
- mongo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:alpine | |
WORKDIR '/usr/app' | |
COPY package*.json ./ | |
RUN npm install | |
COPY ./ ./ | |
EXPOSE 3000 | |
CMD npm start |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
options:{ | |
sort:{ | |
createdAt : -1 //descending order | |
} | |
} | |
// OR | |
options:{ | |
sort:{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.get('/posts',authenticate, async (req,res) => { | |
//const _ispublished = req.query.published; | |
const match = {} | |
const sort = {} | |
if(req.query.published){ | |
match.published = req.query.published === 'true' | |
} | |
if(req.query.sortBy && req.query.OrderBy){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.get('/posts',authenticate, async (req,res) => { | |
//const _ispublished = req.query.published; | |
const match = {} | |
if(req.query.published){ | |
match.published = req.query.published === 'true' | |
} | |
try { | |
await req.user.populate({ | |
path:'posts', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.get('/posts',authenticate, async (req,res) => { | |
//const _ispublished = req.query.published; | |
const match = {} | |
if(req.query.published){ | |
match.published = req.query.published === 'true' | |
} | |
try { | |
await req.user.populate({ | |
path:'posts', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.get('/posts',authenticate, async (req,res) => { | |
try { | |
await req.user.populate('posts).execPopulate() | |
res.send(req.user.posts) | |
} catch (error) { | |
res.status(500).send() | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
updatePost(parent,args, ctx, info){ | |
const post = ctx.posts.find((post) => post.id === args.id) | |
const originalPost = {...post} //spread operator | |
if (!post) { | |
throw new Error('Post not found') | |
} | |
if (typeof args.body === 'string') { | |
post.body = args.body | |
} |