Skip to content

Commit

Permalink
fixed conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Rupeshiya committed Jul 20, 2020
2 parents 2f1eb36 + 6a859e3 commit 97c15bb
Show file tree
Hide file tree
Showing 26 changed files with 1,137 additions and 101 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.git
.github
7 changes: 4 additions & 3 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
PORT=5000
NODE_ENV="development"
JWT_SECRET="thisismysupersecrettokenjustkidding"
DATABASE_URL="mongodb://localhost:27017/donut-development"
SENDGRID_API_KEY = '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'
SOCKET_PORT = 8810
DATABASE_URL="mongodb://mongo:27017/donut-development"
SENDGRID_API_KEY='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'
SOCKET_PORT=8810
clientbaseurl = "http://localhost:3000/"
39 changes: 39 additions & 0 deletions .github/workflows/image-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: donut-server-image-ci

on:
push:
branches:
- development

tags:
- v*

env:
IMAGE_NAME: donut-server:latest
REPO_NAME: codeuino1
REGISTRY_NAME: registry.hub.docker.com

jobs:
push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Build image
run: docker build . --file Dockerfile.prod --tag $IMAGE_NAME

- name: Log into registry
run: docker login --username {{ secrets.DOCKER_USERNAME }} --password {{ secrets.DOCKER_PASSWORD }}
- name: Push image
run: |
IMAGE_ID=$REGISTRY_NAME/$REPO_NAME/$IMAGE_NAME
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:latest
docker push $IMAGE_ID:$VERSION
21 changes: 21 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM node:14

ENV NODE_ENV="development"

# Copy package.json file into container
COPY package.json package.json
COPY package-lock.json package-lock.json

# Install node modules
RUN npm install && \
npm install --only=dev && \
npm cache clean --force --loglevel=error

# Volume to mount source code into container
VOLUME [ "/server" ]

# move to the source code directory
WORKDIR /server

# Start the server
CMD mv ../node_modules . && npm run dev
16 changes: 16 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:14

ENV NODE_ENV="production"

WORKDIR /server

RUN git clone https://github.com/codeuino/social-platform-donut-backend.git

WORKDIR /server/social-platform-donut-backend

RUN npm install && \
npm install pm2@latest -g && \
npm cache clean --force --loglevel=error

# Start the server
CMD [ "pm2", "start", "./bin/www", "--time", "--no-daemon" ]
16 changes: 15 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const cookieParser = require('cookie-parser')
const createError = require('http-errors')
const path = require('path')
const socket = require('socket.io')
const multer = require('multer')
const bodyParser = require('body-parser')
const cors = require('cors')
const fileConstants = require('./config/fileHandlingConstants')

const indexRouter = require('./app/routes/index')
const authRouter = require('./app/routes/auth')
Expand All @@ -16,10 +20,19 @@ const organizationRouter = require('./app/routes/organisation')
const commentRouter = require('./app/routes/comment')
const projectRouter = require('./app/routes/project')
const notificationRouter = require('./app/routes/notification')
const proposalRouter = require('./app/routes/proposal')

const app = express()
const server = require('http').Server(app)

app.use(cors())

app.use(bodyParser.json({ limit: '200mb' }))
app.use(bodyParser.urlencoded(fileConstants.fileParameters))

const memoryStorage = multer.memoryStorage()
app.use(multer({ storage: memoryStorage }).single('file'))

server.listen(process.env.SOCKET_PORT || 8810)
// WARNING: app.listen(80) will NOT work here!

Expand Down Expand Up @@ -54,10 +67,11 @@ app.use('/event', eventRouter)
app.use('/shortUrl', shortUrlRouter)
app.use('/comment', commentRouter)
app.use('/project', projectRouter)
app.use('/proposal', proposalRouter)

// catch 404 and forward to error handler
app.use(function (req, res, next) {
next(createError(404, 'route doesn\'t exist'))
next(createError(404, "route doesn't exist"))
})

// error handler
Expand Down
21 changes: 19 additions & 2 deletions app/controllers/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ const HttpStatus = require('http-status-codes')
const Notifications = require('../models/Notifications')
const helper = require('../utils/paginate')
const User = require('../models/User')
const ProposalNotifications = require('../models/ProposalNotification')

module.exports = {
// GET ALL THE NOTIFICATIONS FOR ALL
getOrgNotifications: async (req, res, next) => {
try {
const notifications = await Notifications.find({}, {}, helper.paginate(req))
const notifications = await Notifications.find(
{},
{},
helper.paginate(req)
)
.lean()
.sort({ createdAt: -1 })
.exec()
Expand All @@ -23,7 +28,9 @@ module.exports = {
try {
const user = await User.findById(userId)
if (!user) {
return res.status(HttpStatus.BAD_REQUEST).json({ msg: 'No such user exists!' })
return res
.status(HttpStatus.BAD_REQUEST)
.json({ msg: 'No such user exists!' })
}
// get all notifications of existing user
const notifications = user.notifications
Expand All @@ -34,5 +41,15 @@ module.exports = {
} catch (error) {
HANDLER.handleError(res, error)
}
},

getProposalNotifications: async (req, res, next) => {
try {
const notifications = await ProposalNotifications.find({})
console.log(notifications)
return res.status(HttpStatus.OK).json({ notifications })
} catch (error) {
HANDLER.handleError(res, error)
}
}
}
Loading

0 comments on commit 97c15bb

Please sign in to comment.