Skip to content

Commit

Permalink
Track separate URL for song and score
Browse files Browse the repository at this point in the history
  • Loading branch information
joneubank committed Aug 5, 2021
1 parent ca4e36e commit 5fb30cb
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 10 deletions.
25 changes: 25 additions & 0 deletions migrations/20210805195658-scoreAndSongUrls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
async up(db, client) {
const datacenters = await db
.collection('Datacenter')
.find({})
.toArray();
const operations = datacenters.map(datacenter => {
return (
datacenter.url &&
db.collection('Datacenter').updateOne(
{ _id: datacenter._id },
{
$set: { songUrl: datacenter.url, scoreUrl: datacenter.url },
$unset: { url: 1 },
},
)
);
});
return Promise.all(operations);
},

async down(db, client) {
// No state to rollback to.
},
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "datacenters-registry",
"version": "0.2.0",
"version": "0.3.0",
"description": "",
"scripts": {
"start": "npm run serve",
Expand Down
7 changes: 5 additions & 2 deletions src/resources/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,16 @@ components:
organization: Acme
storageType: S3
name: Cancer Collaboratory Cloud
url: https://api.example.com
scoreUrl: https://song.example.com
songUrl: https://score.example.com
properties:
contactEmail:
type: string
storageType:
type: string
url:
scoreUrl:
type: string
songUrl:
type: string
centerId:
type: string
Expand Down
38 changes: 31 additions & 7 deletions src/service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
import { Mongoose } from 'mongoose';
/*
* Copyright (c) 2020 The Ontario Institute for Cancer Research. All rights reserved
*
* This program and the accompanying materials are made available under the terms of
* the GNU Affero General Public License v3.0. You should have received a copy of the
* GNU Affero General Public License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

import mongoose from 'mongoose';
import _ from 'lodash';
Expand All @@ -13,7 +30,8 @@ export interface DataCenter {
centerId: string;
storageType: string;
contactEmail: string;
url: string;
songUrl: string;
scoreUrl: string;
}

export type QueryFilters = {
Expand Down Expand Up @@ -75,7 +93,8 @@ export async function update(newDc: DataCenter) {
dc.contactEmail = newDc.contactEmail;
dc.storageType = newDc.storageType;
dc.organization = newDc.organization;
dc.url = newDc.url;
dc.songUrl = newDc.songUrl;
dc.scoreUrl = newDc.scoreUrl;
const updated = await dc.save();
return docToPojo(updated);
}
Expand Down Expand Up @@ -105,8 +124,11 @@ function validateDataCenter(dc: DataCenter) {
throw new Errors.InvalidArgument('storageType is missing');
}

if (!dc.url) {
throw new Errors.InvalidArgument('url is missing');
if (!dc.songUrl) {
throw new Errors.InvalidArgument('songUrl is missing');
}
if (!dc.scoreUrl) {
throw new Errors.InvalidArgument('scoreUrl is missing');
}

if (!dc.contactEmail) {
Expand Down Expand Up @@ -147,7 +169,8 @@ const DataCenterSchema = new mongoose.Schema(
type: { type: String, required: true },
organization: { type: String, required: true },
storageType: { type: String, required: true },
url: { type: String, required: true },
songUrl: { type: String, required: true },
scoreUrl: { type: String, required: true },
contactEmail: { type: String, required: true },
},
{ timestamps: true, minimize: false, optimisticConcurrency: true } as any,
Expand Down Expand Up @@ -186,7 +209,8 @@ function docToPojo(center: DataCenterDocument): DataCenter {
organization: center.organization,
contactEmail: center.contactEmail,
storageType: center.storageType,
url: center.url,
songUrl: center.songUrl,
scoreUrl: center.scoreUrl,
type: center.type,
};
}
Expand Down

0 comments on commit 5fb30cb

Please sign in to comment.