Add a simple receive service based on feathers-sequelize

This commit is contained in:
R. Tyler Croy 2018-09-09 18:42:52 -07:00
parent 13bd07e810
commit 05fe7ceb91
No known key found for this signature in database
GPG Key ID: 1426C7DC3F51E16F
5 changed files with 41 additions and 3 deletions

View File

@ -2,6 +2,7 @@
"host": "localhost",
"port": 3030,
"public": "../public/",
"postgres": "postgres://postgres:jenkinsuplink@db:5432/uplink_development",
"paginate": {
"default": 10,
"max": 50

View File

@ -4,13 +4,16 @@ import fs from 'fs';
import path from 'path';
import Sequelize from 'sequelize';
import logger from '../logger';
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/database')[env];
const config = require(__dirname + '/../../config/database')[env];
const db : any = {};
const sequelize = new Sequelize(config.database, config.username, config.password, config);
const sequelize = new Sequelize(config.url, {
dialect: 'postgres',
});
fs
.readdirSync(__dirname)

View File

@ -1,2 +1,5 @@
import receive from './receive';
export default (app) => {
app.configure(receive);
};

View File

@ -0,0 +1,15 @@
import { HooksObject } from '@feathersjs/feathers';
export const receiveHooks : HooksObject = {
before: {
all: [],
find: [],
get: [],
create: [],
update: [],
patch: [],
remove: []
},
after: {},
error: {},
};

16
src/services/receive.ts Normal file
View File

@ -0,0 +1,16 @@
/*
* The /receive service is responsible receiving the data POSTed from the
* Jenkins instances and storing it in the database
*/
import db from '../models';
import Event from '../models/event';
import service from 'feathers-sequelize';
import { DataTypes } from 'sequelize';
import { receiveHooks } from './receive.hooks';
export default (app) => {
const Model : any = Event(db.sequelize, db.sequelize.Sequelize);
app.use('/receive', service({ Model }));
app.service('receive').hooks(receiveHooks);
};