Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach by Process ID",
"processId": "${command:PickProcess}"
}
]
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ COPY . /app/
# expose port 4040
EXPOSE 4040

# cmd to start service
# cmd to start services
CMD [ "yarn", "start" ]
1 change: 1 addition & 0 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const config = {
port: envVars.PORT,
mongooseDebug: envVars.MONGOOSE_DEBUG,
jwtSecret: envVars.JWT_SECRET,
baseUrl: envVars.BASE_URL,
mongo: {
host: envVars.MONGO_HOST,
port: envVars.MONGO_PORT
Expand Down
9 changes: 9 additions & 0 deletions config/mongoose-faker-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import mongoose from 'mongoose'

export function fakerPlugin(schema, options) {
schema.static('fake', function (modelName) {
let m = mongoose.model(modelName);
console.log(schema.path('requisitions').casterConstructor)
return m;
})
}
4 changes: 2 additions & 2 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ services:
- MONGO_HOST=mongodb://mongo/express-mongoose-es6-rest-api-test
- DEBUG=express-mongoose-es6-rest-api:*

# Link to containers in another service.
# Link to containers in another services.
# Links also express dependency between services in the same way as depends_on,
# so they determine the order of service startup.
# so they determine the order of services startup.
links:
- mongo

Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ services:
- MONGO_HOST=mongodb://mongo/smartface
- DEBUG=smartface:*

# Link to containers in another service.
# Link to containers in another services.
# Links also express dependency between services in the same way as depends_on,
# so they determine the order of service startup.
# so they determine the order of services startup.
links:
- mongo
mongo:
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import util from 'util';
// config should be imported before importing any other file
import config from './config/config';
import app from './config/express';
import {fakePlugin} from './config/mongoose-faker-plugin'

const debug = require('debug')('express-mongoose-es6-rest-api:index');

Expand All @@ -27,6 +28,8 @@ if (config.MONGOOSE_DEBUG) {
});
}

mongoose.plugin(fakePlugin)

// module.parent check is required to support mocha watch
// src: https://github.com/mochajs/mocha/issues/1912
if (!module.parent) {
Expand All @@ -36,4 +39,5 @@ if (!module.parent) {
});
}


export default app;
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"build": "gulp",
"lint": "esw *.js server config --color",
"lint:watch": "yarn lint -- --watch",
"precommit": "yarn lint && yarn test",
"test": "cross-env NODE_ENV=test ./node_modules/.bin/mocha --ui bdd --reporter spec --colors --compilers js:babel-core/register server/tests --recursive",
"test:watch": "yarn test -- --watch",
"test:coverage": "cross-env NODE_ENV=test ./node_modules/.bin/istanbul cover _mocha -- --ui bdd --reporter spec --colors --compilers js:babel-core/register server/tests --recursive",
Expand Down Expand Up @@ -53,13 +52,16 @@
"express-jwt": "5.1.0",
"express-validation": "1.0.1",
"express-winston": "2.1.2",
"faker": "false4.1.0",
"helmet": "3.1.0",
"http-status": "^0.2.0",
"joi": "10.0.6",
"jsonwebtoken": "7.1.9",
"lodash": "^4.17.5",
"method-override": "^2.3.5",
"moment": "false2.20.1",
"mongoose": "4.7.4",
"mongoose-fakery": "false0.1.7",
"morgan": "1.7.0",
"ussd-menu-builder": "false1.0.0",
"winston": "2.3.0"
Expand All @@ -70,7 +72,8 @@
"babel-plugin-add-module-exports": "0.2.1",
"babel-preset-es2015": "6.16.0",
"babel-preset-stage-2": "6.18.0",
"chai": "^3.4.1",
"chai": "false4.1.2",
"chai-http": "false3.0.0",
"commitizen": "^2.9.2",
"coveralls": "^2.11.6",
"cross-env": "3.1.3",
Expand All @@ -89,7 +92,7 @@
"gulp-util": "^3.0.7",
"husky": "^0.13.1",
"istanbul": "1.1.0-alpha.1",
"mocha": "3.2.0",
"mocha": "false5.0.1",
"run-sequence": "^1.1.5",
"supertest": "2.0.1",
"supertest-as-promised": "4.0.2",
Expand Down
7 changes: 7 additions & 0 deletions server/controllers/bid.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {Bid} from "../models/bid.model";

export function get(req, res) {
Bid.find({}, (err, bids) => {
res.json(bids)
})
}
7 changes: 7 additions & 0 deletions server/controllers/operation.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {Operation} from "../models/operation.model";

export function get(req, res) {
Operation.find({}, (err, operations) => {
res.json(operations)
})
}
7 changes: 7 additions & 0 deletions server/controllers/posting.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {Posting} from "../models/posting.model";

export function get(req, res) {
Posting.find({}, (err, postings) => {
res.json(postings)
})
}
22 changes: 0 additions & 22 deletions server/controllers/states/distribution.js

This file was deleted.

55 changes: 0 additions & 55 deletions server/controllers/ussd-menu.js

This file was deleted.

40 changes: 16 additions & 24 deletions server/controllers/ussd.controller.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,27 @@
import menu from './ussd-menu'
import axios from 'axios'
import moment from 'moment'
import menu from '../services/flow/ussd-menu';
import dispatchService from '../services/dispatch-service';

function start(req, res, next) {
menu.run(req.body, ussdResult => {
res.send(ussdResult)
})
menu.run(req.body, (ussdResult) => {
res.send(ussdResult);
});
}

function getDispatchProxy(req, res, next) {
let gin = parseInt(req.query.gin)
let itemType = ['Wheat', 'Duket', 'Furno', 'Fafa', 'Endomi', 'Wetet'][gin]
itemType = itemType ? itemType : 'Wheat'
res.json({
bags: gin + 1,
kg: gin * 100,
itemType,
date: moment().subtract(gin, 'days').calendar(),
truckPlateNumber: gin + '-38765',
})
function getDispatchInfo(req, res, next) {
const gin = parseInt(req.query.gin, 10);
const info = dispatchService.getDispatchInfo(gin);
res.json(info);
}

function getDispatch(req, res, next) {
axios.get('http://localhost:4040/api/ussd/dispatch-proxy?gin=' + req.query.gin).then((axiosResponse) => {
res.json(axiosResponse.data)
})
function getDispatchViaProxy(req, res, next) {
dispatchService.getDispatchInfoViaProxy(req.query.gin).then((dispatch) => {
res.json(dispatch);
});
}

function received(req, res, next) {
//TODO: store the received amount to the database
res.send({})
// TODO: store the received amount to the database
res.send({});
}

export default {start, getDispatch, getDispatchProxy, received}
export default { start, getDispatchInfo, getDispatchViaProxy, received };
32 changes: 32 additions & 0 deletions server/models/account.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import mongoose from 'mongoose'
const Schema = mongoose.Schema
import BaseSchema from './base.schema'
import _ from 'lodash'
import faker from 'faker'

export const AccountSchema = new Schema(_.extend(BaseSchema, {
name: String,
code: Number,
description: String,
}))

AccountSchema.statics = {
fake(n = 1) {
let _faker = () => {
return new Account({
name: faker.name.findName(),
code: faker.random.number(),
description: faker.lorem.sentences
})
}

if(n == 1) return _faker()
let accounts = []
for(let i = 0; i < n; i++) {
accounts.push(_faker())
}
return accounts
}
}

export const Account = mongoose.model('Account', AccountSchema)
9 changes: 9 additions & 0 deletions server/models/base.schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const BaseSchema = {
id: Number,
created_at: Date,
updated_at: Date,
created_by: Number,
modified_by: Number,
deleted: Boolean,
deleted_at: Date,
}
47 changes: 47 additions & 0 deletions server/models/bid.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import mongoose from 'mongoose'
const Schema = mongoose.Schema
import _ from 'lodash'
import faker from 'faker'
import BaseSchema from './base.schema'
import {Quote, QuoteSchema} from './quote.model'

export const BidSchema = new Schema(_.extend(BaseSchema, {
framework_tender_id: Number,
region_id: Number,
bid_number: Number,
bid_bond_format: Number,
start_date: Date,
closing_date: Date,
opening_date: Date,
status: Number,
remark: String,
quotes: [QuoteSchema]
}))

BidSchema.statics = {
fake(n = 1) {
let _fake = () => {
return new Bid({
framework_tender_id: faker.random.number(),
region_id: faker.random.number(),
bid_number: faker.random.number(),
bid_bond_format: faker.random.number(),
start_date: faker.date.recent(),
closing_date: faker.date.recent(),
opening_date: faker.date.recent(),
status: faker.random.number(),
remark: faker.lorem.sentences(),
quotes: Quote.fake(3)
})
}

if(n == 1) return _fake()
let bids = []
for(let i = 0; i < n; i++) {
bids.push(_fake())
}
return bids
}
}

export const Bid = mongoose.model('Bid', BidSchema)
Loading