Archived
2

introduced first_id to reference new template versions to original

This commit is contained in:
VLE2FE 2020-05-29 15:24:24 +02:00
parent ea336f4ebc
commit 0fcb902499
7 changed files with 29 additions and 20 deletions

View File

@ -165,14 +165,6 @@ Template:
min: 0
max: 2
ConditionTemplate:
allOf:
- $ref: 'api.yaml#/components/schemas/Template'
properties:
number_prefix:
type: string
example: B
Email:
properties:
email:

View File

@ -14,7 +14,7 @@
schema:
type: array
items:
$ref: 'api.yaml#/components/schemas/ConditionTemplate'
$ref: 'api.yaml#/components/schemas/Template'
401:
$ref: 'api.yaml#/components/responses/401'
500:
@ -36,7 +36,7 @@
content:
application/json:
schema:
$ref: 'api.yaml#/components/schemas/ConditionTemplate'
$ref: 'api.yaml#/components/schemas/Template'
401:
$ref: 'api.yaml#/components/responses/401'
404:
@ -56,14 +56,14 @@
content:
application/json:
schema:
$ref: 'api.yaml#/components/schemas/ConditionTemplate'
$ref: 'api.yaml#/components/schemas/Template'
responses:
200:
description: condition details
content:
application/json:
schema:
$ref: 'api.yaml#/components/schemas/ConditionTemplate'
$ref: 'api.yaml#/components/schemas/Template'
400:
$ref: 'api.yaml#/components/responses/400'
401:
@ -88,14 +88,14 @@
content:
application/json:
schema:
$ref: 'api.yaml#/components/schemas/ConditionTemplate'
$ref: 'api.yaml#/components/schemas/Template'
responses:
200:
description: condition details
content:
application/json:
schema:
$ref: 'api.yaml#/components/schemas/ConditionTemplate'
$ref: 'api.yaml#/components/schemas/Template'
400:
$ref: 'api.yaml#/components/responses/400'
401:

View File

@ -1,6 +1,7 @@
import mongoose from 'mongoose';
const ConditionTemplateSchema = new mongoose.Schema({
first_id: mongoose.Schema.Types.ObjectId,
name: String,
version: Number,
parameters: [{

View File

@ -1,6 +1,7 @@
import mongoose from 'mongoose';
const MeasurementTemplateSchema = new mongoose.Schema({
first_id: mongoose.Schema.Types.ObjectId,
name: String,
version: Number,
parameters: [{

View File

@ -133,7 +133,8 @@ describe('/template', () => {
if (err) return done(err);
TemplateConditionModel.findById(res.body._id).lean().exec((err, data:any) => {
if (err) return done(err);
should(data).have.only.keys('_id', 'name', 'version', 'parameters', '__v');
should(data).have.only.keys('_id', 'first_id', 'name', 'version', 'parameters', '__v');
should(data.first_id.toString()).be.eql('200000000000000000000001');
should(data).have.property('name', 'heat aging');
should(data).have.property('version', 2);
should(data).have.property('parameters').have.lengthOf(1);
@ -155,7 +156,8 @@ describe('/template', () => {
if (err) return done(err);
TemplateConditionModel.findById(res.body._id).lean().exec((err, data:any) => {
if (err) return done(err);
should(data).have.only.keys('_id', 'name', 'version', 'parameters', '__v');
should(data).have.only.keys('_id', 'first_id', 'name', 'version', 'parameters', '__v');
should(data.first_id.toString()).be.eql('200000000000000000000001');
should(data).have.property('name', 'heat aging');
should(data).have.property('version', 2);
should(data).have.property('parameters').have.lengthOf(2);
@ -315,7 +317,8 @@ describe('/template', () => {
if (err) return done(err);
TemplateConditionModel.findById(res.body._id).lean().exec((err, data:any) => {
if (err) return done(err);
should(data).have.only.keys('_id', 'name', 'version', 'parameters', '__v');
should(data).have.only.keys('_id', 'first_id', 'name', 'version', 'parameters', '__v');
should(data.first_id.toString()).be.eql(data._id.toString());
should(data).have.property('name', 'heat aging');
should(data).have.property('version', 1);
should(data).have.property('parameters').have.lengthOf(1);
@ -556,7 +559,8 @@ describe('/template', () => {
should(_.omit(res.body, '_id')).be.eql({name: 'IR spectrum', version: 2, parameters: [{name: 'data point table', range: {min: 0, max: 1000}}]});
TemplateMeasurementModel.findById(res.body._id).lean().exec((err, data:any) => {
if (err) return done(err);
should(data).have.only.keys('_id', 'name', 'version', 'parameters', '__v');
should(data).have.only.keys('_id', 'first_id', 'name', 'version', 'parameters', '__v');
should(data.first_id.toString()).be.eql('300000000000000000000001');
should(data).have.property('name', 'IR spectrum');
should(data).have.property('version', 2);
should(data).have.property('parameters').have.lengthOf(1);
@ -580,7 +584,8 @@ describe('/template', () => {
should(_.omit(res.body, '_id')).be.eql({name: 'IR spectrum', version: 2, parameters: [{name: 'dpt', range: {type: 'array'}}]});
TemplateMeasurementModel.findById(res.body._id).lean().exec((err, data:any) => {
if (err) return done(err);
should(data).have.only.keys('_id', 'name', 'version', 'parameters', '__v');
should(data).have.only.keys('_id', 'first_id', 'name', 'version', 'parameters', '__v');
should(data.first_id.toString()).be.eql('300000000000000000000001');
should(data).have.property('name', 'IR spectrum');
should(data).have.property('version', 2);
should(data).have.property('parameters').have.lengthOf(1);
@ -731,7 +736,8 @@ describe('/template', () => {
TemplateMeasurementModel.find({name: 'vz'}).lean().exec((err, data:any) => {
if (err) return done(err);
should(data).have.lengthOf(1);
should(data[0]).have.only.keys('_id', 'name', 'version', 'parameters', '__v');
should(data[0]).have.only.keys('_id', 'first_id', 'name', 'version', 'parameters', '__v');
should(data[0].first_id.toString()).be.eql(data[0]._id.toString());
should(data[0]).have.property('name', 'vz');
should(data[0]).have.property('version', 1);
should(data[0]).have.property('parameters').have.lengthOf(1);

View File

@ -6,6 +6,7 @@ import ConditionTemplateModel from '../models/condition_template';
import MeasurementTemplateModel from '../models/measurement_template';
import res400 from './validate/res400';
import IdValidate from './validate/id';
import mongoose from "mongoose";
@ -65,6 +66,8 @@ router.post('/template/:collection(measurement|condition)/new', async (req, res,
const {error, value: template} = TemplateValidate.input(req.body, 'new');
if (error) return res400(error, res);
template._id = mongoose.Types.ObjectId(); // set reference to itself for first version of template
template.first_id = template._id;
template.version = 1; // set template version
await new (model(req))(template).save((err, data) => {
if (err) next (err);

View File

@ -423,6 +423,7 @@
"condition_templates": [
{
"_id": {"$oid":"200000000000000000000001"},
"first_id": {"$oid":"200000000000000000000001"},
"name": "heat treatment",
"version": 1,
"parameters": [
@ -447,6 +448,7 @@
},
{
"_id": {"$oid":"200000000000000000000002"},
"first_id": {"$oid":"200000000000000000000001"},
"name": "heat treatment 2",
"version": 2,
"parameters": [
@ -459,6 +461,7 @@
},
{
"_id": {"$oid":"200000000000000000000003"},
"first_id": {"$oid":"200000000000000000000003"},
"name": "raw material",
"version": 1,
"parameters": [
@ -469,6 +472,7 @@
"measurement_templates": [
{
"_id": {"$oid":"300000000000000000000001"},
"first_id": {"$oid":"300000000000000000000001"},
"name": "spectrum",
"version": 1,
"parameters": [
@ -483,6 +487,7 @@
},
{
"_id": {"$oid":"300000000000000000000002"},
"first_id": {"$oid":"300000000000000000000001"},
"name": "kf",
"version": 2,
"parameters": [
@ -505,6 +510,7 @@
},
{
"_id": {"$oid":"300000000000000000000003"},
"first_id": {"$oid":"300000000000000000000003"},
"name": "mt 3",
"version": 1,
"parameters": [