Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2fca174483 |
@@ -13,6 +13,8 @@ import * as project from './project/project'
|
||||
import * as projectReport from './project/project_report'
|
||||
import * as projectMeta from './project/project_meta'
|
||||
import * as chart from './configuration/chart'
|
||||
import * as subject from './subject/subject'
|
||||
import * as subjectData from './subject/subject_data'
|
||||
|
||||
export default {
|
||||
upload,
|
||||
@@ -29,5 +31,7 @@ export default {
|
||||
project,
|
||||
projectReport,
|
||||
projectMeta,
|
||||
chart
|
||||
chart,
|
||||
subject,
|
||||
subjectData
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import SubjectModel from '../../models/subject/subject'
|
||||
|
||||
const subject = new SubjectModel()
|
||||
|
||||
export const create = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
console.log('create', data)
|
||||
const result = await subject.create(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const update = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await subject.update(data, id)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const get = async (ctx, next) => {
|
||||
const configurationType = ctx.query.type
|
||||
const id = ctx.query.id
|
||||
const library = ctx.query.library
|
||||
const query = { id: id, library: library }
|
||||
const result = await subject.get(configurationType, query)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const clearDeleted = async (ctx, next) => {
|
||||
const controllerID = ctx.params.controller_id
|
||||
const result = await subject.clearDeleted(controllerID)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import SubjectDataModel from '../../models/subject/subject_data'
|
||||
|
||||
const subjectData = new SubjectDataModel()
|
||||
|
||||
export const create = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const result = await subjectData.create(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const update = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await subjectData.update(data, id)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const get = async (ctx, next) => {
|
||||
const subjectId = ctx.query.subject_id
|
||||
const meta = ctx.query.meta
|
||||
console.log('subject get', subjectId, meta)
|
||||
const query = {}
|
||||
if (subjectId) query.subject_id = subjectId
|
||||
if (meta) query.meta = meta
|
||||
const result = await subjectData.get(query)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const clearDeleted = async (ctx, next) => {
|
||||
const controllerID = ctx.params.controller_id
|
||||
const result = await subjectData.clearDeleted(controllerID)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
@@ -32,6 +32,8 @@ db.project_reports = require('./schema/project_report.model')(sequelize, Sequeli
|
||||
db.project_metas = require('./schema/project_meta.model')(sequelize, Sequelize)
|
||||
db.recording_data_metas = require('./schema/recording_data_meta.model')(sequelize, Sequelize)
|
||||
db.charts = require('./schema/configuration/chart.model')(sequelize, Sequelize)
|
||||
db.subjects = require('./schema/subject/subject.model')(sequelize, Sequelize)
|
||||
db.subject_datas = require('./schema/subject/subject_data.model')(sequelize, Sequelize)
|
||||
for (let i = 0; i < 32; i++) {
|
||||
db[i + '_recording_data_raws'] = require('./schema/recording_data_raw.model')(sequelize, Sequelize, i)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@ module.exports = (sequelize, Sequelize) => {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
subject: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: []
|
||||
},
|
||||
uuid: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const Subject = sequelize.define('subject', {
|
||||
name: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
description: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
cache: {
|
||||
type: Sequelize.JSONB
|
||||
},
|
||||
user_auth: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
return Subject
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const SubjectData = sequelize.define('subject_datas', {
|
||||
subject_id: {
|
||||
type: Sequelize.INTEGER
|
||||
},
|
||||
mode: {
|
||||
type: Sequelize.JSONB
|
||||
},
|
||||
data: {
|
||||
type: Sequelize.JSONB
|
||||
},
|
||||
user_auth: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
owner: [],
|
||||
maintainer: [],
|
||||
guest: []
|
||||
}
|
||||
},
|
||||
meta: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
project: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
},
|
||||
created_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
},
|
||||
updated_at: {
|
||||
type: Sequelize.DATE,
|
||||
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP')
|
||||
}
|
||||
},
|
||||
{
|
||||
timestamps: false
|
||||
})
|
||||
|
||||
return SubjectData
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
const db = require('../../db/database')
|
||||
|
||||
const Op = db.Sequelize.Op
|
||||
|
||||
class SubjectModel {
|
||||
async create (req) {
|
||||
return db.subjects.create(
|
||||
req
|
||||
)
|
||||
}
|
||||
|
||||
async update (req, id) {
|
||||
if (id != null) {
|
||||
const ret = await db.subjects.update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
} else {
|
||||
const ret = await db.subjects.update(
|
||||
req,
|
||||
{
|
||||
where: {}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
async clearDeleted () {
|
||||
const ret = await db.subjects.destroy(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async get (type, query) {
|
||||
let where = {}
|
||||
if (type === 'chart') {
|
||||
where = {
|
||||
chart: {
|
||||
[Op.ne]: null
|
||||
}
|
||||
}
|
||||
}
|
||||
Object.assign(query, where)
|
||||
const ret = await db.subjects.findAll(
|
||||
{
|
||||
where: where
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByQueryWithAttrs (query, limit, offset, order, attrs, group) {
|
||||
const attrList = attrs ? attrs.split('-') : undefined
|
||||
const ret = await db.subjects.findAll(
|
||||
{
|
||||
// where: db.Sequelize.where(db.Sequelize.fn('DATE', db.Sequelize.col('created_at')), '2022-12-02'),
|
||||
where: query,
|
||||
attributes: attrList,
|
||||
order: order,
|
||||
limit: limit,
|
||||
offset: offset
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
export default SubjectModel
|
||||
@@ -0,0 +1,70 @@
|
||||
const db = require('../../db/database')
|
||||
|
||||
const Op = db.Sequelize.Op
|
||||
|
||||
class SubjectDataModel {
|
||||
async create (req) {
|
||||
return db.charts.create(
|
||||
req
|
||||
)
|
||||
}
|
||||
|
||||
async update (req, id) {
|
||||
if (id != null) {
|
||||
const ret = await db.subject_datas.update(
|
||||
req,
|
||||
{
|
||||
where: {
|
||||
id: id
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
} else {
|
||||
const ret = await db.subject_datas.update(
|
||||
req,
|
||||
{
|
||||
where: {}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
async clearDeleted () {
|
||||
const ret = await db.subject_datas.destroy(
|
||||
{
|
||||
where: {
|
||||
deleted: true
|
||||
}
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async get (query) {
|
||||
const ret = await db.subject_datas.findAll(
|
||||
{
|
||||
where: query
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
|
||||
async getByQueryWithAttrs (query, limit, offset, order, attrs, group) {
|
||||
const attrList = attrs ? attrs.split('-') : undefined
|
||||
const ret = await db.subject_datas.findAll(
|
||||
{
|
||||
// where: db.Sequelize.where(db.Sequelize.fn('DATE', db.Sequelize.col('created_at')), '2022-12-02'),
|
||||
where: query,
|
||||
attributes: attrList,
|
||||
order: order,
|
||||
limit: limit,
|
||||
offset: offset
|
||||
}
|
||||
)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
|
||||
export default SubjectDataModel
|
||||
@@ -143,3 +143,15 @@ export default router
|
||||
.post('/api/configuration/update/:id', controllers.chart.update)
|
||||
.get('/api/configuration/get', controllers.chart.get)
|
||||
.get('/api/configuration/clear_deleted/', controllers.chart.clearDeleted)
|
||||
|
||||
// subject
|
||||
.post('/api/subject/create', controllers.subject.create)
|
||||
.post('/api/subject/update/:id', controllers.subject.update)
|
||||
.get('/api/subject/get', controllers.subject.get)
|
||||
.get('/api/subject/clear_deleted/', controllers.subject.clearDeleted)
|
||||
|
||||
// subject_data
|
||||
.post('/api/subject_data/create', controllers.subjectData.create)
|
||||
.post('/api/subject_data/update/:id', controllers.subjectData.update)
|
||||
.get('/api/subject_data/get', controllers.subjectData.get)
|
||||
.get('/api/subject_data/clear_deleted/', controllers.subjectData.clearDeleted)
|
||||
|
||||
Reference in New Issue
Block a user