Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/schemas/microservice.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ const microserviceCreate = {
"minLength": 1
},
"config": {"type": "string"},
"catalogItemId": {"type": "integer"},
"catalogItemId": {
"type": "integer",
"minimum": 4
},
"flowId": {"type": "integer"},
"iofogUuid": {"type": "string"},
"rootHostAccess": {"type": "boolean"},
Expand Down
26 changes: 20 additions & 6 deletions src/services/catalog-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,15 @@ const updateCatalogItem = async function (id, data, user, isCLI, transaction) {
await Validator.validate(data, Validator.schemas.catalogItemUpdate);

const where = isCLI
? {id: id}
: {id: id, userId: user.id};
? {
id: id,
[Op.or]: [{category: {[Op.ne]: 'SYSTEM'}}, {category: null}]
}
: {
id: id,
userId: user.id,
[Op.or]: [{category: {[Op.ne]: 'SYSTEM'}}, {category: null}]
};

data.id = id;
await _updateCatalogItem(data, where, transaction);
Expand All @@ -55,7 +62,7 @@ const updateCatalogItem = async function (id, data, user, isCLI, transaction) {

const listCatalogItems = async function (user, isCLI, transaction) {
const where = isCLI
? {[Op.or]: [{category: {[Op.ne]: 'SYSTEM'}}, {category: null}]}
? {}
: {
[Op.or]: [{userId: user.id}, {userId: null}],
[Op.or]: [{category: {[Op.ne]: 'SYSTEM'}}, {category: null}]
Expand All @@ -73,7 +80,7 @@ const listCatalogItems = async function (user, isCLI, transaction) {

const getCatalogItem = async function (id, user, isCLI, transaction) {
const where = isCLI
? {[Op.or]: [{category: {[Op.ne]: 'SYSTEM'}}, {category: null}]}
? {}
: {
[Op.or]: [{userId: user.id}, {userId: null}],
[Op.or]: [{category: {[Op.ne]: 'SYSTEM'}}, {category: null}]
Expand All @@ -92,8 +99,15 @@ const getCatalogItem = async function (id, user, isCLI, transaction) {

const deleteCatalogItem = async function (id, user, isCLI, transaction) {
const where = isCLI
? {id: id}
: {userId: user.id, id: id};
? {
id: id,
[Op.or]: [{category: {[Op.ne]: 'SYSTEM'}}, {category: null}]
}
: {
userId: user.id,
id: id,
[Op.or]: [{category: {[Op.ne]: 'SYSTEM'}}, {category: null}]
};
const affectedRows = await CatalogItemManager.delete(where, transaction);
if (affectedRows === 0) {
throw new Errors.NotFoundError(AppHelper.formatMessage(ErrorMessages.INVALID_CATALOG_ITEM_ID, id));
Expand Down