Skip to content

Commit

Permalink
Merge pull request #96 from ferrumnet/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
zikriya authored May 20, 2022
2 parents e736596 + e7660bd commit 107fef5
Show file tree
Hide file tree
Showing 60 changed files with 2,618 additions and 6,727 deletions.
103 changes: 103 additions & 0 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Build, Upload and Deploy

on:
push:
branches:
- develop
pull_request:

env:
AppName: gateway-backend
Region: us-east-2

jobs:
Build:
runs-on: ubuntu-latest
env:
s3-bucket: ferrum-gateway-pipeline-artifacts-dev
s3-filename: dev-aws-codedeploy-${{ github.sha }}
Environment: dev
AppName: gateway-backend
# strategy:
# matrix:
# # python-version: [3.8]
# # node-version: ['12.x']
# # appname: ['aws-codedeploy']
# # deploy-group: ['staging']
# s3-bucket: ['ferrum-pipeline-artifacts']
# s3-filename: ['staging-aws-codedeploy-${{ github.sha }}']
# AppName: ['gateway-backend']
# Environment: ['dev']

steps:
- name: checkout code
uses: actions/checkout@v2

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build, tag, and push image to Amazon ECR
run: |
docker build -t ${{ secrets.ECR_REGISTRY }}:latest .
docker push ${{ secrets.ECR_REGISTRY }}:latest
- name: AWS Deploy push
run: |
echo "export Region=${{ env.Region }}" >> set_env.sh
echo "export Environment=${{ env.Environment }}" >> set_env.sh
echo "export AppName=${{ env.AppName }}" >> set_env.sh
echo "export ECR_REGISTRY=${{ secrets.ECR_REGISTRY }}" >> set_env.sh
aws deploy push \
--application-name gateway-backend-dev \
--s3-location s3://${{ env.s3-bucket }}/${{ env.s3-filename }}.zip \
--source .
# --description "This is a revision for the ${{ matrix.appname }}-${{ github.sha }}" \
# --ignore-hidden-files \
Deploy:
needs: [Build]
runs-on: ubuntu-latest
env:
s3-bucket: ferrum-gateway-pipeline-artifacts-dev
s3-filename: dev-aws-codedeploy-${{ github.sha }}
Environment: dev
AppName: gateway-backend
steps:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-2


- name: CodeDeploy Deployment Api
id: deploy_api
run: |
aws deploy create-deployment \
--application-name ${{ secrets.CODE_DEPLOY_APP }} \
--deployment-group-name ${{ secrets.DEPLOYMENT_GROUP_API }} \
--deployment-config-name CodeDeployDefault.OneAtATime \
--s3-location bucket=${{ env.s3-bucket }},key=${{ env.s3-filename }}.zip,bundleType=zip
# --github-location repository=${{ github.repository }},commitId=${{ github.sha }}
- name: CodeDeploy Deployment Cron
id: deploy_cron
run: |
aws deploy create-deployment \
--application-name ${{ secrets.CODE_DEPLOY_APP }} \
--deployment-group-name ${{ secrets.DEPLOYMENT_GROUP_CRON }} \
--deployment-config-name CodeDeployDefault.OneAtATime \
--s3-location bucket=${{ env.s3-bucket }},key=${{ env.s3-filename }}.zip,bundleType=zip
# --github-location repository=${{ github.repository }},commitId=${{ github.sha }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ public/
/.serverless
dockerBuild.sh
package-lock.json
config/config.json
15 changes: 4 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
FROM node:16

# Create app directory
WORKDIR /usr/src/app
WORKDIR /app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
COPY . /app

RUN npm install
# If you are building your code for production
# RUN npm ci --only=production

# Bundle app source
COPY . .

EXPOSE 8080
CMD [ "node", "server.js" ]

CMD [ "node", "server.js" ]
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Gateway Backend

install latest node packages
install latest npm packages
sudo npm i
nodemone server.js or node server.js
app will run on 8080 port, you can update in server.js
1. Install latest node packages
2. Install latest npm packages
3. sudo npm i
4. nodemone server.js [env] [type]
5. env can be: dev || qa || uat || staging || prod
6. type can be: api || cron
7. For example: nodemone server.js dev api
8. node server.js [env] [type]
9. pm2 start server.js -- [env] [type] --name "server"
10. App will run on 8080 port, you can update in server.js
29 changes: 25 additions & 4 deletions app/controllers/api/v1/admin/competitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module.exports = function (router) {
req.body.startDateAfterDelay = moment(req.body.startDate).utc().add(10,'seconds')
req.body.endDateAfterDelay = moment(req.body.endDate).utc().add(10,'seconds')
req.body.user = req.user._id
req.body.updatedByUser = req.user._id
req.body.organization = req.user.organization
// delete req.body.startBlock
// delete req.body.endBlock

Expand All @@ -45,10 +47,11 @@ module.exports = function (router) {
let filter = {}
filter = { _id: req.params.id }

if (!req.body.name || !req.body.leaderboard || !req.body.startDate || !req.body.endDate) {
return res.http400('name & leaderboard & startDate & endDate are required.');
if (!req.body.name) {
return res.http400('name is required.');
}
req.body.nameInLower = (req.body.name).toLowerCase()
req.body.updatedByUser = req.user._id
req.body.updatedAt = new Date()
req.body.startDateAfterDelay = moment(req.body.startDate).utc().add(10,'seconds')
req.body.endDateAfterDelay = moment(req.body.endDate).utc().add(10,'seconds')
Expand Down Expand Up @@ -86,7 +89,7 @@ module.exports = function (router) {
return res.http400('status is required.');
}

let competition = await db.Competitions.findOneAndUpdate(filter, {status: req.body.status, updatedAt: new Date()}, { new: true });
let competition = await db.Competitions.findOneAndUpdate(filter, {status: req.body.status, updatedAt: new Date(), updatedByUser : req.user._id}, { new: true });

res.http200({
competition: competition
Expand All @@ -97,7 +100,7 @@ module.exports = function (router) {
router.get('/list', async (req, res) => {

var filter = {}
filter.user = req.user._id
filter.organization = req.user.organization

db.Competitions.find(filter)
.sort({ createdAt: -1 })
Expand All @@ -111,6 +114,24 @@ module.exports = function (router) {

});

router.get("/participants/growth/:competition",asyncMiddleware(async (req, res) => {
let filter = {competition: req.params.competition}
let participants = []
let sort = { rank: 1 }
if(req.query.excludedWalletAddress){
filter.excludedWalletAddress = req.query.excludedWalletAddress == "true" ? true : false
}
if (req.query.isPagination != null && req.query.isPagination == 'false') {
participants = await db.CompetitionGrowthTracker.find(filter).sort(sort)
} else {
participants = await db.CompetitionGrowthTracker.find(filter).sort(sort)
.skip(req.query.offset ? parseInt(req.query.offset) : 0)
.limit(req.query.limit ? parseInt(req.query.limit) : 10)
}
return res.http200({ participants });
})
)

router.get('/:id', async (req, res) => {

let filter = {}
Expand Down
30 changes: 2 additions & 28 deletions app/controllers/api/v1/admin/currencies.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

const { db, asyncMiddleware, commonFunctions, stringHelper } = global
const { db, asyncMiddleware, commonFunctions, stringHelper, currencyHelper } = global
const mailer = global.mailer;
var jwt = require('jsonwebtoken');
var mongoose = require('mongoose');
Expand Down Expand Up @@ -33,7 +33,7 @@ module.exports = function (router) {


let currency = await db.Currencies.create(req.body)
currency.currencyAddressesByNetwork = await createCurrencyAddresses(req, currency, req.body)
currency.currencyAddressesByNetwork = await currencyHelper.createCurrencyAddresses(req, currency, req.body)
currency = await db.Currencies.findOneAndUpdate({ _id: currency }, currency, { new: true });

return res.http200({
Expand Down Expand Up @@ -149,30 +149,4 @@ module.exports = function (router) {

});

async function createCurrencyAddresses(req, model, body) {

let results = []
if (model && body.networks && body.networks.length > 0) {
for (let i = 0; i < body.networks.length; i++) {
if (body.networks[i].tokenContractAddress) {
body.networks[i].tokenContractAddress = (body.networks[i].tokenContractAddress).toLowerCase()
}
let innerBody = {
network: body.networks[i].network,
currency: model._id,
networkDex: body.networks[i].networkDex,
tokenContractAddress: body.networks[i].tokenContractAddress,
createdByOrganization: req.user.organization
}
let result = await db.CurrencyAddressesByNetwork.create(innerBody)
results.push(result._id)
// let count = await db.CurrencyAddressesByNetwork.count({ network: body.networks[i].network, currency: model._id })
// if (count == 0) {
// }
}
}

return results
}

};
9 changes: 7 additions & 2 deletions app/controllers/api/v1/admin/leaderboards.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ module.exports = function (router) {

req.body.exclusionWalletAddressList = convertListIntoLowercase(req.body.exclusionWalletAddressList)
req.body.user = req.user._id
req.body.createdByUser = req.user._id
req.body.updatedByUser = req.user._id
req.body.organization = req.user.organization
req.body.nameInLower = (req.body.name).toLowerCase()
req.body.createdAt = new Date()
req.body.updatedAt = new Date()

let leaderboard = await db.Leaderboards.create(req.body)
leaderboard.leaderboardCurrencyAddressesByNetwork = await createLeaderboardCurrencyAddressesByNetwork(req.body, leaderboard)
Expand Down Expand Up @@ -65,6 +69,7 @@ module.exports = function (router) {

req.body.exclusionWalletAddressList = convertListIntoLowercase(req.body.exclusionWalletAddressList)
req.body.nameInLower = (req.body.name).toLowerCase()
req.body.updatedByUser = req.user._id
req.body.updatedAt = new Date()

let leaderboard = await db.Leaderboards.findOneAndUpdate(filter, req.body, { new: true });
Expand All @@ -84,7 +89,7 @@ module.exports = function (router) {
return res.http400('status is required.');
}

let leaderboard = await db.Leaderboards.findOneAndUpdate(filter, { status: req.body.status, updatedAt: new Date() }, { new: true });
let leaderboard = await db.Leaderboards.findOneAndUpdate(filter, { status: req.body.status, updatedAt: new Date(), updatedByUser : req.user._id }, { new: true });

res.http200({
leaderboard: leaderboard
Expand All @@ -95,7 +100,7 @@ module.exports = function (router) {
router.get('/list', async (req, res) => {

var filter = {}
filter.user = req.user._id
filter.organization = req.user.organization

db.Leaderboards.find(filter)
.populate({
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/admin/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function (router) {
req.body.createdByUser = req.user._id

req.body.nameInLower = (req.body.name).toLowerCase()
req.body.createdAt = new Date()
req.body.createdAt,req.body.updatedAt = new Date()

const step = await db.Steps.create(req.body)

Expand Down
23 changes: 21 additions & 2 deletions app/controllers/api/v1/admin/stepsFlow.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@ module.exports = function (router) {

req.body.nameInLower = (req.body.name).toLowerCase()

req.body.createdAt = new Date()
req.body.createdAt,req.body.updatedAt = new Date()

if(req.body.productId){

const product = await db.products.findById(req.body.productId);

if(!product){
return res.http400('invalid product detail provided.');
}

}


if(req.body.stepFlowSteps){

for (stepFlowStepId of req.body.stepFlowSteps){
Expand Down Expand Up @@ -99,6 +108,16 @@ module.exports = function (router) {

const stepFlow = await db.StepsFlow.findOne(filter);

if(req.body.productId){

const product = await db.products.findById(req.body.productId);

if(!product){
return res.http400('invalid product detail provided.');
}

}

if(stepFlow){

if(req.body.name){
Expand Down
Loading

0 comments on commit 107fef5

Please sign in to comment.