Skip to content

Instantly share code, notes, and snippets.

@ZiiSolutions
Created August 8, 2017 15:32
Show Gist options
  • Save ZiiSolutions/b6da7499f3e6d5dbd3a199110db1812a to your computer and use it in GitHub Desktop.
Save ZiiSolutions/b6da7499f3e6d5dbd3a199110db1812a to your computer and use it in GitHub Desktop.
'use strict';
const oldSportSubServiceMap = require('../../config/mapping/old-sport-sub-services.json');
const sportObjectMap = require('../../config/mapping/sport-objects.json');
const OBJECT_CODE = "paoperation:disable-publication";
const OBJECT_NAME = 'Disable Publication';
const OBJECT_REL = 'operation';
const OBJECT_PROFILE = 'paoperation';
const OBJECT_SCHEME = 'http://content-repository/v1/object';
const SPORT_UK_CODE = 'paservice:sport:uk';
const SPORT_UK_NAME = 'UK';
const SPORT_UK_REL = 'partOf';
const SPORT_UK_PROFILE = 'paservice';
const SPORT_UK_SCHEME = 'http://content-repository/v1/subject';
function addDisableRepublishObject(item) {
// remove any existing disable publication operation flag
item.object = (item.object || []).filter(o => o.code !== OBJECT_CODE);
// publication is disabled so add publication operation flag
item.object.push({
code: OBJECT_CODE,
name: OBJECT_NAME,
rel: OBJECT_REL,
profile: OBJECT_PROFILE,
scheme: OBJECT_SCHEME
});
}
module.exports.select = function () {
return {
uri: 'a58a341f-c1cb-418d-8254-e4b65950248-foo'
};
// return {
// subject: {
// $all: [
// {$elemMatch: {code: 'paservice:sport', profile: 'paservice'}}
// ]
// }
// };
};
module.exports.sort = function () {
return 'versioncreated';
};
module.exports.transform = function (item) {
item.subject = item.subject || [];
addDisableRepublishObject(item);
addSportObjects(item);
//
// Object.keys(oldSportSubServiceMap).map((k) => {
// Object.keys(item.subject).map((l) => {
// if (item.subject[l].hasOwnProperty('code') && item.subject[l].code === oldSportSubServiceMap[k].code) {
// if (k !== 'other' && k !== 'football') {
// item.subject.splice(l, 1);
// addSportUKServiceObject(item);
// }
// }
// });
// });
item.type = 'foo';
console.log(item);
return item;
};
function addSportObjects(item){
Object.keys(oldSportSubServiceMap).map((k) => {
if (k !== 'other') {
if (item.subject.indexOf(oldSportSubServiceMap[k]) === -1) {
item.subject.push(sportObjectMap[k])
}
}
});
}
function addSportUKServiceObject(item) {
item.subject = (item.subject || []).filter(o => o.code !== SPORT_UK_CODE);
item.subject.push({
code: SPORT_UK_CODE,
name: SPORT_UK_NAME,
rel: SPORT_UK_REL,
profile: SPORT_UK_PROFILE,
scheme: SPORT_UK_SCHEME
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment