Commit d5b4f9dc by luyt

track backend

0 parents
'use strict';
module.exports = {
write: true,
prefix: '^',
plugin: 'autod-egg',
test: [
'test',
'benchmark',
],
dep: [
'egg',
'egg-scripts',
],
devdep: [
'egg-ci',
'egg-bin',
'egg-mock',
'autod',
'autod-egg',
'eslint',
'eslint-config-egg',
],
exclude: [
'./test/fixtures',
'./dist',
],
};
{
"extends": "eslint-config-egg"
}
logs/
npm-debug.log
yarn-error.log
node_modules/
package-lock.json
yarn.lock
coverage/
.idea/
run/
.DS_Store
*.sw*
*.un~
typings/
.nyc_output/
.github
language: node_js
node_js:
- '10'
before_install:
- npm i npminstall@5 -g
install:
- npminstall
script:
- npm run ci
after_script:
- npminstall codecov && codecov
# tracking-backend
## QuickStart
<!-- add docs here for user -->
see [egg docs][egg] for more detail.
### Development
```bash
$ npm i
$ npm run dev
$ open http://localhost:7001/
```
### Deploy
```bash
$ npm start
$ npm stop
```
### npm scripts
- Use `npm run lint` to check code style.
- Use `npm test` to run unit test.
- Use `npm run autod` to auto detect dependencies upgrade, see [autod](https://www.npmjs.com/package/autod) for more detail.
[egg]: https://eggjs.org
\ No newline at end of file
'use strict';
const Controller = require('egg').Controller;
class HomeController extends Controller {
async index() {
const { ctx } = this;
ctx.body = 'hi, egg';
}
}
module.exports = HomeController;
'use strict';
const Controller = require('egg').Controller;
class TrackController extends Controller {
async create() {
const { ctx } = this;
// console.log('ctx.request.body: ', ctx.request.body);
// 定义创建项目接口的请求参数规则
const createRule = {
info: {
type: 'array',
itemType: 'object',
required: false,
rule: {
exta: 'string?',
// id: 'number',
accountName: 'string?',
userName: 'string?',
accountType: 'number?',
accountLevel: 'number?',
userType: 'number?',
merchantId: 'number?',
merchantName: 'string?',
admin: 'boolean?',
merchantModel: 'number?',
sapCode: { type: 'number', required: false },
status: 'number?',
staffAvatar: { type: 'string', required: false },
isMerchantStaffAdmin: { type: 'boolean', required: false },
token: 'string?',
},
},
// merchant_name: 'number?',
// account_level: 'string?',
// merchant_id: 'number?',
// time_on_page: 'dateTime?',
// query_parameters: 'string?',
// channel_name: 'string?',
// choose_specialist: 'string?',
// welcome_message_code: 'string?',
// qr_code_link: 'string?',
// channel_id: 'number?',
// how_to_specify: 'string?',
// customer_information: 'string?',
// send_group_message: 'string?',
// welcome_message_market: 'string?',
// sop_name: 'string?',
// marketing_time: 'dateTime?',
// marketing_people: 'string?',
// update_crowd: 'string?',
// marketing_content: 'string?',
// marketing_channels: 'string?',
// follow_employees: 'string?',
// part_times: 'number?',
// select_group_account: 'string?',
// select_customer: 'string?',
// bulk_content: 'string?',
// send_time: 'dateTime?',
// group_name_group: 'string?',
// choose_owner_group: 'string?',
// bulk_content_group: 'string?',
// send_time_group: 'dateTime?',
// exta: 'string?',
// page_url: 'string?',
};
try {
ctx.validate(createRule, ctx.request.body);
const result = await ctx.service.trackService.create(ctx.request.body);
ctx.body = result;
} catch (error) {
ctx.body = {
code: error.code,
message: error.message,
};
}
}
// 查询列表
async list() {
// todo 分页 page pageSize
// const page = ctx.query.page || 1;
//
// 分页
const { ctx } = this;
const result = await ctx.service.trackService.list(ctx.query);
ctx.body = result;
}
}
module.exports = TrackController;
'use strict';
module.exports = app => {
const { INTEGER, STRING, BOOLEAN } = app.Sequelize;
const Track = app.model.define('info', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
exta: STRING(255),
accountName: STRING(100),
userName: STRING(100),
accountType: INTEGER,
accountLevel: INTEGER,
userType: INTEGER,
merchantId: INTEGER,
merchantName: STRING(100),
admin: BOOLEAN,
merchantModel: INTEGER,
sapCode: INTEGER,
status: INTEGER,
staffAvatar: STRING(100),
isMerchantStaffAdmin: BOOLEAN,
token: STRING(100),
// info: STRING(255),
// // 公共模块
// merchant_name: STRING(10),
// account_level: STRING(10),
// merchant_id: INTEGER,
// time_on_page: DATE,
// query_parameters: STRING(255),
// // 引流获客
// channel_name: STRING(10),
// choose_specialist: STRING(10),
// welcome_message_code: STRING(255),
// qr_code_link: STRING(20),
// channel_id: INTEGER,
// how_to_specify: STRING(10),
// customer_information: STRING(100),
// send_group_message: STRING(50),
// welcome_message_market: STRING(50),
// // 营销转化
// sop_name: STRING(10),
// marketing_time: DATE,
// marketing_people: STRING(50),
// update_crowd: STRING(50),
// marketing_content: STRING(100),
// marketing_channels: STRING(10),
// follow_employees: STRING(10),
// part_times: INTEGER,
// select_group_account: STRING(10),
// select_customer: STRING(255),
// bulk_content: STRING(255),
// send_time: DATE,
// group_name_group: STRING(10),
// choose_owner_group: STRING(10),
// bulk_content_group: STRING(255),
// send_time_group: DATE,
// // 额外的业务数据
// exta: STRING(255),
// // 页面路径
// page_url: STRING(20),
// // create_date: DATE,
// // update_date: DATE,
}, {
timestamps: true,
createdAt: 'create_date',
updatedAt: 'update_date',
});
return Track;
};
'use strict';
/**
* @param {Egg.Application} app - egg application
*/
module.exports = app => {
const { router, controller } = app;
router.get('/', controller.home.index);
// 监控信息收集
router.post('/track', controller.track.create);
router.get('/list', controller.track.list);
};
'use strict';
const Service = require('egg').Service;
class TrackService extends Service {
async create(params) {
// console.log('params: ', params);
const { app } = this;
// const result = await app.model.Track.create(
// // {
// // ...params,
// // }
// );
const result = await app.model.Track.bulkCreate(
params.info
);
console.log('result: ', result);
if (result) {
return {
code: 200,
message: '新增成功',
data: '',
};
}
return {
code: -1,
message: '新增失败',
data: '',
};
}
async list(params) {
// console.log('params: ', params);
const { app } = this;
// 分页
const blogPageList = await app.model.Track.findAll({
// order: [
// [ 'id', 'desc' ],
// ],
limit: +params.pageSize || 10,
offset: +params.page || 1,
});
return {
code: 200,
message: '查询成功',
data: blogPageList || [],
};
}
}
module.exports = TrackService;
environment:
matrix:
- nodejs_version: '10'
install:
- ps: Install-Product node $env:nodejs_version
- npm i npminstall@5 && node_modules\.bin\npminstall
test_script:
- node --version
- npm --version
- npm run test
build: off
/* eslint valid-jsdoc: "off" */
'use strict';
/**
* @param {Egg.EggAppInfo} appInfo app info
*/
module.exports = appInfo => {
/**
* built-in config
* @type {Egg.EggAppConfig}
**/
const config = exports = {};
// use for cookie sign key, should change to your own and keep security
// config.keys = appInfo.name + '_1655953567969_2906';
config.security = {
csrf: {
enable: false,
},
domainWhiteList: [ '*' ],
};
config.cors = {
origin: '*',
allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
};
config.sequelize = {
dialect: 'mysql', // support: mysql, mariadb, postgres, mssql
timezone: '+08:00', // 时区问题
database: 'track_info',
host: '192.168.3.210',
port: 3308,
username: 'user_frontend',
password: 'fdfew80w',
define: {
underscored: false,
freezeTableName: true,
timestamps: false,
},
};
// add your middleware config here
config.middleware = [];
// add your user config here
const userConfig = {
// myAppName: 'egg',
};
// ip访问
config.cluster = {
listen: {
// path: '',
// port: 7001,
hostname: '0.0.0.0',
},
};
return {
...config,
...userConfig,
};
};
'use strict';
/** @type Egg.EggPlugin */
module.exports = {
// had enabled by egg
// static: {
// enable: true,
// }
// 跨域配置
cors: {
enable: true,
package: 'egg-cors',
},
sequelize: {
enable: true,
package: 'egg-sequelize',
},
// 数据格式校验
validate: {
enable: true,
package: 'egg-validate',
},
};
{
"include": [
"**/*"
]
}
\ No newline at end of file
{
"name": "tracking-backend",
"version": "1.0.0",
"description": "",
"private": true,
"egg": {
"declarations": true
},
"dependencies": {
"egg": "^2.15.1",
"egg-cors": "^2.2.3",
"egg-scripts": "^2.11.0",
"egg-sequelize": "^6.0.0",
"egg-validate": "^2.0.2",
"mysql2": "^2.3.3"
},
"devDependencies": {
"autod": "^3.0.1",
"autod-egg": "^1.1.0",
"egg-bin": "^4.11.0",
"egg-ci": "^1.11.0",
"egg-mock": "^3.21.0",
"eslint": "^5.13.0",
"eslint-config-egg": "^7.1.0"
},
"engines": {
"node": ">=10.0.0"
},
"scripts": {
"start": "egg-scripts start --daemon --title=egg-server-tracking-backend",
"stop": "egg-scripts stop --title=egg-server-tracking-backend",
"dev": "egg-bin dev",
"debug": "egg-bin debug",
"test": "npm run lint -- --fix && npm run test-local",
"test-local": "egg-bin test",
"cov": "egg-bin cov",
"lint": "eslint .",
"ci": "npm run lint && npm run cov",
"autod": "autod"
},
"ci": {
"version": "10"
},
"repository": {
"type": "git",
"url": ""
},
"author": "",
"license": "MIT"
}
'use strict';
const { app, assert } = require('egg-mock/bootstrap');
describe('test/app/controller/home.test.js', () => {
it('should assert', () => {
const pkg = require('../../../package.json');
assert(app.config.keys.startsWith(pkg.name));
// const ctx = app.mockContext({});
// yield ctx.service.xx();
});
it('should GET /', () => {
return app.httpRequest()
.get('/')
.expect('hi, egg')
.expect(200);
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!