Archived
2

DELETE and GET methods for condition

This commit is contained in:
VLE2FE 2020-05-08 15:12:36 +02:00
parent 852c035dfc
commit 0ec9b44462
7 changed files with 767 additions and 8 deletions

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="dataSourceStorageLocal">
<data-source name="@localhost" uuid="46f112fc-d60d-4217-873f-f5ffea06180c">
<database-info product="Mongo DB" version="4.2.5" jdbc-version="4.2" driver-name="MongoDB JDBC Driver" driver-version="1.7.1" dbms="MONGO" exact-version="4.2.5" exact-driver-version="1.7" />
<case-sensitivity plain-identifiers="mixed" quoted-identifiers="mixed" />
<secret-storage>master_key</secret-storage>
<schema-mapping>
<introspection-scope>
<node kind="schema" negative="1" />
</introspection-scope>
</schema-mapping>
</data-source>
</component>
</project>

View File

@ -0,0 +1,584 @@
<?xml version="1.0" encoding="UTF-8"?>
<dataSource name="@localhost">
<database-model serializer="dbm" dbms="MONGO" family-id="MONGO" format-version="4.18">
<root id="1">
<ServerVersion>4.2.5</ServerVersion>
</root>
<schema id="2" parent="1" name="admin"/>
<schema id="3" parent="1" name="config"/>
<schema id="4" parent="1" name="dfopdb"/>
<schema id="5" parent="1" name="dfopdb_test"/>
<schema id="6" parent="1" name="local"/>
<schema id="7" parent="1" name="test">
<Current>1</Current>
</schema>
<table id="8" parent="3" name="system.sessions"/>
<table id="9" parent="4" name="materials"/>
<table id="10" parent="4" name="measurement_templates"/>
<table id="11" parent="4" name="note_fields"/>
<table id="12" parent="4" name="notes"/>
<table id="13" parent="4" name="samples"/>
<table id="14" parent="4" name="treatment_templates"/>
<table id="15" parent="4" name="users"/>
<table id="16" parent="5" name="materials"/>
<table id="17" parent="5" name="measurement_templates"/>
<table id="18" parent="5" name="note_fields"/>
<table id="19" parent="5" name="notes"/>
<table id="20" parent="5" name="samples"/>
<table id="21" parent="5" name="treatment_templates"/>
<table id="22" parent="5" name="users"/>
<table id="23" parent="6" name="startup_log"/>
<table id="24" parent="7" name="a"/>
<table id="25" parent="7" name="b"/>
<column id="26" parent="9" name="_id">
<DataType>ObjectId(0)|12s</DataType>
</column>
<column id="27" parent="9" name="__v">
<Position>1</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="28" parent="9" name="carbon_fiber">
<Position>2</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="29" parent="9" name="glass_fiber">
<Position>3</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="30" parent="9" name="group">
<Position>4</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="31" parent="9" name="mineral">
<Position>5</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="32" parent="9" name="name">
<Position>6</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="33" parent="9" name="numbers">
<Position>7</Position>
<DataType>list(0)|4999545s</DataType>
</column>
<column id="34" parent="9" name="numbers._id">
<Position>8</Position>
<DataType>ObjectId(0)|12s</DataType>
</column>
<column id="35" parent="9" name="numbers.color">
<Position>9</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="36" parent="9" name="numbers.number">
<Position>10</Position>
<DataType>Double(0)|8s</DataType>
</column>
<column id="37" parent="9" name="supplier">
<Position>11</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="38" parent="12" name="_id">
<DataType>ObjectId(0)|12s</DataType>
</column>
<column id="39" parent="12" name="__v">
<Position>1</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="40" parent="12" name="comment">
<Position>2</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="41" parent="12" name="sample_references">
<Position>3</Position>
<DataType>list(0)|4999545s</DataType>
</column>
<column id="42" parent="13" name="_id">
<DataType>ObjectId(0)|12s</DataType>
</column>
<column id="43" parent="13" name="__v">
<Position>1</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="44" parent="13" name="batch">
<Position>2</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="45" parent="13" name="color">
<Position>3</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="46" parent="13" name="material_id">
<Position>4</Position>
<DataType>ObjectId(0)|12s</DataType>
</column>
<column id="47" parent="13" name="note_id">
<Position>5</Position>
<DataType>ObjectId(0)|12s</DataType>
</column>
<column id="48" parent="13" name="number">
<Position>6</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="49" parent="13" name="type">
<Position>7</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="50" parent="13" name="user_id">
<Position>8</Position>
<DataType>ObjectId(0)|12s</DataType>
</column>
<column id="51" parent="15" name="_id">
<DataType>ObjectId(0)|12s</DataType>
</column>
<column id="52" parent="15" name="__v">
<Position>1</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="53" parent="15" name="device_name">
<Position>2</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="54" parent="15" name="email">
<Position>3</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="55" parent="15" name="key">
<Position>4</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="56" parent="15" name="level">
<Position>5</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="57" parent="15" name="location">
<Position>6</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="58" parent="15" name="name">
<Position>7</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="59" parent="15" name="pass">
<Position>8</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="60" parent="16" name="_id">
<DataType>ObjectId(0)|12s</DataType>
</column>
<column id="61" parent="16" name="__v">
<Position>1</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="62" parent="16" name="carbon_fiber">
<Position>2</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="63" parent="16" name="glass_fiber">
<Position>3</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="64" parent="16" name="group">
<Position>4</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="65" parent="16" name="mineral">
<Position>5</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="66" parent="16" name="name">
<Position>6</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="67" parent="16" name="numbers">
<Position>7</Position>
<DataType>list(0)|4999545s</DataType>
</column>
<column id="68" parent="16" name="numbers.color">
<Position>8</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="69" parent="16" name="numbers.number">
<Position>9</Position>
<DataType>Double(0)|8s</DataType>
</column>
<column id="70" parent="16" name="supplier">
<Position>10</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="71" parent="17" name="_id">
<DataType>ObjectId(0)|12s</DataType>
</column>
<column id="72" parent="17" name="name">
<Position>1</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="73" parent="17" name="parameters">
<Position>2</Position>
<DataType>list(0)|4999545s</DataType>
</column>
<column id="74" parent="17" name="parameters.name">
<Position>3</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="75" parent="17" name="parameters.range">
<Position>4</Position>
<DataType>map(0)|4999544s</DataType>
</column>
<column id="76" parent="17" name="parameters.range.max">
<Position>5</Position>
<DataType>Double(0)|8s</DataType>
</column>
<column id="77" parent="17" name="parameters.range.min">
<Position>6</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="78" parent="18" name="_id">
<DataType>ObjectId(0)|12s</DataType>
</column>
<column id="79" parent="18" name="__v">
<Position>1</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="80" parent="18" name="name">
<Position>2</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="81" parent="18" name="qty">
<Position>3</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="82" parent="19" name="_id">
<DataType>ObjectId(0)|12s</DataType>
</column>
<column id="83" parent="19" name="__v">
<Position>1</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="84" parent="19" name="comment">
<Position>2</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="85" parent="19" name="custom_fields">
<Position>3</Position>
<DataType>map(0)|4999544s</DataType>
</column>
<column id="86" parent="19" name="custom_fields.another_field">
<Position>4</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="87" parent="19" name="custom_fields.not allowed for new applications">
<Position>5</Position>
<DataType>Boolean|12s</DataType>
</column>
<column id="88" parent="19" name="sample_references">
<Position>6</Position>
<DataType>list(0)|4999545s</DataType>
</column>
<column id="89" parent="19" name="sample_references.id">
<Position>7</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="90" parent="19" name="sample_references.relation">
<Position>8</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="91" parent="20" name="_id">
<DataType>ObjectId(0)|12s</DataType>
</column>
<column id="92" parent="20" name="__v">
<Position>1</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="93" parent="20" name="batch">
<Position>2</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="94" parent="20" name="color">
<Position>3</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="95" parent="20" name="material_id">
<Position>4</Position>
<DataType>ObjectId(0)|12s</DataType>
</column>
<column id="96" parent="20" name="note_id">
<Position>5</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="97" parent="20" name="number">
<Position>6</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="98" parent="20" name="type">
<Position>7</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="99" parent="20" name="user_id">
<Position>8</Position>
<DataType>ObjectId(0)|12s</DataType>
</column>
<column id="100" parent="20" name="validated">
<Position>9</Position>
<DataType>Boolean|12s</DataType>
</column>
<column id="101" parent="21" name="_id">
<DataType>ObjectId(0)|12s</DataType>
</column>
<column id="102" parent="21" name="name">
<Position>1</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="103" parent="21" name="parameters">
<Position>2</Position>
<DataType>list(0)|4999545s</DataType>
</column>
<column id="104" parent="21" name="parameters.name">
<Position>3</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="105" parent="21" name="parameters.range">
<Position>4</Position>
<DataType>map(0)|4999544s</DataType>
</column>
<column id="106" parent="21" name="parameters.range.max">
<Position>5</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="107" parent="21" name="parameters.range.min">
<Position>6</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="108" parent="21" name="parameters.range.values">
<Position>7</Position>
<DataType>array(0)|2003s</DataType>
</column>
<column id="109" parent="22" name="_id">
<DataType>ObjectId(0)|12s</DataType>
</column>
<column id="110" parent="22" name="__v">
<Position>1</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="111" parent="22" name="device_name">
<Position>2</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="112" parent="22" name="email">
<Position>3</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="113" parent="22" name="key">
<Position>4</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="114" parent="22" name="level">
<Position>5</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="115" parent="22" name="location">
<Position>6</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="116" parent="22" name="name">
<Position>7</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="117" parent="22" name="pass">
<Position>8</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="118" parent="23" name="_id">
<DataType>String(0)|12s</DataType>
</column>
<column id="119" parent="23" name="buildinfo">
<Position>1</Position>
<DataType>map(0)|4999544s</DataType>
</column>
<column id="120" parent="23" name="buildinfo.allocator">
<Position>2</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="121" parent="23" name="buildinfo.bits">
<Position>3</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="122" parent="23" name="buildinfo.buildEnvironment">
<Position>4</Position>
<DataType>map(0)|4999544s</DataType>
</column>
<column id="123" parent="23" name="buildinfo.buildEnvironment.cc">
<Position>5</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="124" parent="23" name="buildinfo.buildEnvironment.ccflags">
<Position>6</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="125" parent="23" name="buildinfo.buildEnvironment.cxx">
<Position>7</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="126" parent="23" name="buildinfo.buildEnvironment.cxxflags">
<Position>8</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="127" parent="23" name="buildinfo.buildEnvironment.distarch">
<Position>9</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="128" parent="23" name="buildinfo.buildEnvironment.distmod">
<Position>10</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="129" parent="23" name="buildinfo.buildEnvironment.linkflags">
<Position>11</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="130" parent="23" name="buildinfo.buildEnvironment.target_arch">
<Position>12</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="131" parent="23" name="buildinfo.buildEnvironment.target_os">
<Position>13</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="132" parent="23" name="buildinfo.debug">
<Position>14</Position>
<DataType>Boolean|12s</DataType>
</column>
<column id="133" parent="23" name="buildinfo.gitVersion">
<Position>15</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="134" parent="23" name="buildinfo.javascriptEngine">
<Position>16</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="135" parent="23" name="buildinfo.maxBsonObjectSize">
<Position>17</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="136" parent="23" name="buildinfo.modules">
<Position>18</Position>
<DataType>list(0)|4999545s</DataType>
</column>
<column id="137" parent="23" name="buildinfo.openssl">
<Position>19</Position>
<DataType>map(0)|4999544s</DataType>
</column>
<column id="138" parent="23" name="buildinfo.openssl.running">
<Position>20</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="139" parent="23" name="buildinfo.storageEngines">
<Position>21</Position>
<DataType>array(0)|2003s</DataType>
</column>
<column id="140" parent="23" name="buildinfo.sysInfo">
<Position>22</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="141" parent="23" name="buildinfo.targetMinOS">
<Position>23</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="142" parent="23" name="buildinfo.version">
<Position>24</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="143" parent="23" name="buildinfo.versionArray">
<Position>25</Position>
<DataType>array(0)|2003s</DataType>
</column>
<column id="144" parent="23" name="cmdLine">
<Position>26</Position>
<DataType>map(0)|4999544s</DataType>
</column>
<column id="145" parent="23" name="cmdLine.config">
<Position>27</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="146" parent="23" name="cmdLine.net">
<Position>28</Position>
<DataType>map(0)|4999544s</DataType>
</column>
<column id="147" parent="23" name="cmdLine.net.bindIp">
<Position>29</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="148" parent="23" name="cmdLine.net.port">
<Position>30</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="149" parent="23" name="cmdLine.service">
<Position>31</Position>
<DataType>Boolean|12s</DataType>
</column>
<column id="150" parent="23" name="cmdLine.storage">
<Position>32</Position>
<DataType>map(0)|4999544s</DataType>
</column>
<column id="151" parent="23" name="cmdLine.storage.dbPath">
<Position>33</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="152" parent="23" name="cmdLine.storage.journal">
<Position>34</Position>
<DataType>map(0)|4999544s</DataType>
</column>
<column id="153" parent="23" name="cmdLine.storage.journal.enabled">
<Position>35</Position>
<DataType>Boolean|12s</DataType>
</column>
<column id="154" parent="23" name="cmdLine.systemLog">
<Position>36</Position>
<DataType>map(0)|4999544s</DataType>
</column>
<column id="155" parent="23" name="cmdLine.systemLog.destination">
<Position>37</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="156" parent="23" name="cmdLine.systemLog.logAppend">
<Position>38</Position>
<DataType>Boolean|12s</DataType>
</column>
<column id="157" parent="23" name="cmdLine.systemLog.path">
<Position>39</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="158" parent="23" name="hostname">
<Position>40</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="159" parent="23" name="pid">
<Position>41</Position>
<DataType>Long(0)|12s</DataType>
</column>
<column id="160" parent="23" name="startTime">
<Position>42</Position>
<DataType>Date(0)|91s</DataType>
</column>
<column id="161" parent="23" name="startTimeLocal">
<Position>43</Position>
<DataType>String(0)|12s</DataType>
</column>
<column id="162" parent="24" name="_id">
<DataType>ObjectId(0)|12s</DataType>
</column>
<column id="163" parent="24" name="x">
<Position>1</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="164" parent="24" name="y">
<Position>2</Position>
<DataType>Integer|4s</DataType>
</column>
<column id="165" parent="25" name="_id">
<DataType>ObjectId(0)|12s</DataType>
</column>
<column id="166" parent="25" name="s">
<Position>1</Position>
<DataType>String(0)|12s</DataType>
</column>
</database-model>
</dataSource>

View File

@ -2,7 +2,7 @@
parameters:
- $ref: 'api.yaml#/components/parameters/Id'
get:
summary: TODO condition by id
summary: condition by id
description: 'Auth: all, levels: read, write, maintain, dev, admin'
tags:
- /condition
@ -74,7 +74,7 @@
/condition/new:
post:
summary: TODO add condition
summary: add condition
description: 'Auth: basic, levels: write, maintain, dev, admin <br>Only maintain and admin are allowed to reference samples created by another user'
tags:
- /condition

View File

@ -9,7 +9,7 @@ describe('/condition', () => {
beforeEach(done => server = TestHelper.beforeEach(server, done));
afterEach(done => TestHelper.afterEach(server, done));
describe('GET /condition/id', () => {
describe('GET /condition/{id}', () => {
it('returns the right condition', done => {
TestHelper.request(server, done, {
method: 'get',
@ -19,10 +19,117 @@ describe('/condition', () => {
res: {_id: '700000000000000000000001', sample_id: '400000000000000000000001', number: 'B1', parameters: {material: 'copper', weeks: 3}, treatment_template: '200000000000000000000001'}
});
});
it('returns the right condition for an API key');
it('rejects an invalid id');
it('rejects an unknown id');
it('rejects unauthorized requests');
it('returns the right condition for an API key', done => {
TestHelper.request(server, done, {
method: 'get',
url: '/condition/700000000000000000000001',
auth: {key: 'janedoe'},
httpStatus: 200,
res: {_id: '700000000000000000000001', sample_id: '400000000000000000000001', number: 'B1', parameters: {material: 'copper', weeks: 3}, treatment_template: '200000000000000000000001'}
});
});
it('rejects an invalid id', done => {
TestHelper.request(server, done, {
method: 'get',
url: '/condition/70000000000t000000000001',
auth: {basic: 'janedoe'},
httpStatus: 404
});
});
it('rejects an unknown id', done => {
TestHelper.request(server, done, {
method: 'get',
url: '/condition/000000000000000000000001',
auth: {basic: 'janedoe'},
httpStatus: 404
});
});
it('rejects unauthorized requests', done => {
TestHelper.request(server, done, {
method: 'get',
url: '/condition/700000000000000000000001',
httpStatus: 401
});
});
});
describe('DELETE /condition/{id}', () => {
it('deletes the condition', done => {
TestHelper.request(server, done, {
method: 'delete',
url: '/condition/700000000000000000000002',
auth: {basic: 'janedoe'},
httpStatus: 200
}).end((err, res) => {
if (err) return done(err);
should(res.body).be.eql({status: 'OK'});
ConditionModel.findById('700000000000000000000002').lean().exec((err, data) => {
if (err) return done(err);
should(data).be.null();
done();
});
});
});
it('rejects a deleting a condition referenced by measurements');
it('rejects an invalid id', done => {
TestHelper.request(server, done, {
method: 'delete',
url: '/condition/70000000000w000000000002',
auth: {basic: 'janedoe'},
httpStatus: 404
});
});
it('rejects an API key', done => {
TestHelper.request(server, done, {
method: 'delete',
url: '/condition/700000000000000000000002',
auth: {key: 'janedoe'},
httpStatus: 401
});
});
it('rejects requests from a read user', done => {
TestHelper.request(server, done, {
method: 'delete',
url: '/condition/700000000000000000000002',
auth: {basic: 'user'},
httpStatus: 403
});
});
it('rejects a write user deleting a condition belonging to a sample of another user', done => {
TestHelper.request(server, done, {
method: 'delete',
url: '/condition/700000000000000000000003',
auth: {basic: 'janedoe'},
httpStatus: 403
});
});
it('accepts an maintain/admin user deleting a condition belonging to a sample of another user', done => {
TestHelper.request(server, done, {
method: 'delete',
url: '/condition/700000000000000000000002',
auth: {basic: 'admin'},
httpStatus: 200
}).end((err, res) => {
if (err) return done(err);
should(res.body).be.eql({status: 'OK'});
done();
});
});
it('returns 404 for an unknown id', done => {
TestHelper.request(server, done, {
method: 'delete',
url: '/condition/00000000000w000000000002',
auth: {basic: 'janedoe'},
httpStatus: 404
});
});
it('rejects unauthorized requests', done => {
TestHelper.request(server, done, {
method: 'delete',
url: '/condition/700000000000000000000002',
httpStatus: 401
});
});
});
describe('POST /condition/new', () => {

View File

@ -7,10 +7,41 @@ import res400 from './validate/res400';
import SampleModel from '../models/sample';
import ConditionModel from '../models/condition';
import TreatmentTemplateModel from '../models/treatment_template';
import IdValidate from './validate/id';
const router = express.Router();
router.get('/condition/' + IdValidate.parameter(), (req, res, next) => {
if (!req.auth(res, ['read', 'write', 'maintain', 'dev', 'admin'], 'all')) return;
ConditionModel.findById(req.params.id).lean().exec((err, data) => {
if (err) return next(err);
if (data) {
res.json(ConditionValidate.output(data));
}
else {
res.status(404).json({status: 'Not found'});
}
});
});
router.delete('/condition/' + IdValidate.parameter(), (req, res, next) => {
if (!req.auth(res, ['write', 'maintain', 'dev', 'admin'], 'basic')) return;
ConditionModel.findById(req.params.id).lean().exec(async (err, data: any) => {
if (err) return next(err);
if (!data) {
res.status(404).json({status: 'Not found'});
}
if (!await sampleIdCheck(data, req, res, next)) return;
ConditionModel.findByIdAndDelete(req.params.id).lean().exec(async err => {
if (err) return next(err);
res.json({status: 'OK'});
});
});
});
router.post('/condition/new', async (req, res, next) => {
if (!req.auth(res, ['write', 'maintain', 'dev', 'admin'], 'basic')) return;

View File

@ -80,7 +80,7 @@ router.delete('/material/' + IdValidate.parameter(), (req, res, next) => {
MaterialModel.findByIdAndDelete(req.params.id).lean().exec((err, data) => {
if (err) return next(err);
if (data) {
res.json({status: 'OK'})
res.json({status: 'OK'});
}
else {
res.status(404).json({status: 'Not found'});

View File

@ -194,6 +194,28 @@
},
"treatment_template": {"$oid":"200000000000000000000001"},
"__v": 0
},
{
"_id": {"$oid":"700000000000000000000002"},
"sample_id": {"$oid":"400000000000000000000002"},
"number": "B1",
"parameters": {
"material": "copper",
"weeks": 3
},
"treatment_template": {"$oid":"200000000000000000000001"},
"__v": 0
},
{
"_id": {"$oid":"700000000000000000000003"},
"sample_id": {"$oid":"400000000000000000000004"},
"number": "B1",
"parameters": {
"material": "copper",
"weeks": 3
},
"treatment_template": {"$oid":"200000000000000000000001"},
"__v": 0
}
],
"treatment_templates": [