slot fill filter now looks at libraryTags not tags
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
export default function getSlotFillFilter({slot, libraryIds}){
|
||||
export default function getSlotFillFilter({ slot, libraryIds }) {
|
||||
|
||||
if (!slot) throw 'Slot is required';
|
||||
if (!libraryIds) throw 'LibraryIds is required';
|
||||
|
||||
let filter = {
|
||||
removed: {$ne: true},
|
||||
removed: { $ne: true },
|
||||
$and: []
|
||||
};
|
||||
if (libraryIds){
|
||||
filter['ancestors.id'] = {$in: libraryIds};
|
||||
}
|
||||
if (slot.slotType){
|
||||
filter['ancestors.id'] = { $in: libraryIds };
|
||||
if (slot.slotType) {
|
||||
filter.$and.push({
|
||||
$or: [{
|
||||
type: slot.slotType
|
||||
},{
|
||||
}, {
|
||||
type: 'slotFiller',
|
||||
slotFillerType: slot.slotType,
|
||||
}]
|
||||
@@ -19,7 +21,7 @@ export default function getSlotFillFilter({slot, libraryIds}){
|
||||
filter.$and.push({
|
||||
$or: [{
|
||||
type: 'classLevel',
|
||||
},{
|
||||
}, {
|
||||
type: 'slotFiller',
|
||||
slotFillerType: 'classLevel',
|
||||
}]
|
||||
@@ -30,33 +32,33 @@ export default function getSlotFillFilter({slot, libraryIds}){
|
||||
|
||||
// Only search for levels the class needs
|
||||
if (slot.missingLevels && slot.missingLevels.length) {
|
||||
filter.level = {$in: slot.missingLevels};
|
||||
filter.level = { $in: slot.missingLevels };
|
||||
} else {
|
||||
filter.level = (slot.level || 0) + 1;
|
||||
}
|
||||
}
|
||||
let tagsOr = [];
|
||||
let tagsNin = [];
|
||||
if (slot.slotTags && slot.slotTags.length){
|
||||
tagsOr.push({tags: {$all: slot.slotTags}});
|
||||
if (slot.slotTags && slot.slotTags.length) {
|
||||
tagsOr.push({ libraryTags: { $all: slot.slotTags } });
|
||||
}
|
||||
if (slot.extraTags && slot.extraTags.length){
|
||||
if (slot.extraTags && slot.extraTags.length) {
|
||||
slot.extraTags.forEach(extra => {
|
||||
if (!extra.tags || !extra.tags.length) return;
|
||||
if (extra.operation === 'OR'){
|
||||
tagsOr.push({tags: {$all: extra.tags}});
|
||||
} else if (extra.operation === 'NOT'){
|
||||
if (extra.operation === 'OR') {
|
||||
tagsOr.push({ libraryTags: { $all: extra.tags } });
|
||||
} else if (extra.operation === 'NOT') {
|
||||
tagsNin.push(...extra.tags);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (tagsOr.length){
|
||||
if (tagsOr.length) {
|
||||
filter.$or = tagsOr;
|
||||
}
|
||||
if (tagsNin.length){
|
||||
filter.$and.push({tags: {$nin: tagsNin}});
|
||||
if (tagsNin.length) {
|
||||
filter.$and.push({ libraryTags: { $nin: tagsNin } });
|
||||
}
|
||||
if (!filter.$and.length){
|
||||
if (!filter.$and.length) {
|
||||
delete filter.$and;
|
||||
}
|
||||
return filter;
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import { assert } from 'chai';
|
||||
import getSlotFillFilter from '/imports/api/creature/creatureProperties/methods/getSlotFillFilter.js';
|
||||
|
||||
describe('Slot fill filter', function () {
|
||||
|
||||
it('Gives error if arguments aren\'t provided', function () {
|
||||
assert.throws(
|
||||
() => getSlotFillFilter(undefined),
|
||||
null, null, 'Passing undefined should give an error'
|
||||
);
|
||||
assert.throws(
|
||||
() => getSlotFillFilter({
|
||||
slot: { slotTags: ['tag1'] },
|
||||
}),
|
||||
null, null, 'Passing no libraryIds should give an error'
|
||||
);
|
||||
assert.throws(
|
||||
() => getSlotFillFilter({
|
||||
libraryIds: ['libraryId1'],
|
||||
}),
|
||||
null, null, 'Passing no slot should give an error'
|
||||
);
|
||||
});
|
||||
|
||||
it('filters using basic slot tags', function () {
|
||||
const filter = getSlotFillFilter({
|
||||
slot: {
|
||||
slotTags: ['tag1', 'tag2']
|
||||
},
|
||||
libraryIds: ['libraryId1', 'libraryId2']
|
||||
});
|
||||
assert.deepStrictEqual(filter, {
|
||||
$or: [{
|
||||
libraryTags: { $all: ['tag1', 'tag2'] }
|
||||
}],
|
||||
'ancestors.id': { $in: ['libraryId1', 'libraryId2'] },
|
||||
removed: { $ne: true },
|
||||
});
|
||||
});
|
||||
|
||||
it('filters using slot type', function () {
|
||||
const filter = getSlotFillFilter({
|
||||
slot: {
|
||||
slotTags: ['tag1', 'tag2'],
|
||||
slotType: 'feature',
|
||||
},
|
||||
libraryIds: ['libraryId1', 'libraryId2']
|
||||
});
|
||||
assert.deepStrictEqual(filter.$and, [{
|
||||
$or: [{
|
||||
type: 'feature'
|
||||
}, {
|
||||
type: 'slotFiller',
|
||||
slotFillerType: 'feature',
|
||||
}],
|
||||
}]);
|
||||
});
|
||||
|
||||
it('filters using extra tags', function () {
|
||||
const filter = getSlotFillFilter({
|
||||
slot: {
|
||||
slotTags: ['tag1', 'tag2'],
|
||||
extraTags: [
|
||||
{ operation: 'OR', tags: ['tag3', 'tag4'] },
|
||||
{ operation: 'NOT', tags: ['tag5', 'tag6'] },
|
||||
{ operation: 'NOT', tags: ['tag7', 'tag8'] },
|
||||
],
|
||||
},
|
||||
libraryIds: ['libraryId1', 'libraryId2']
|
||||
});
|
||||
assert.deepStrictEqual(filter, {
|
||||
$or: [
|
||||
{ libraryTags: { $all: ['tag1', 'tag2'] } },
|
||||
{ libraryTags: { $all: ['tag3', 'tag4'] } },
|
||||
],
|
||||
$and: [
|
||||
{ libraryTags: { $nin: ['tag5', 'tag6', 'tag7', 'tag8'] } },
|
||||
],
|
||||
'ancestors.id': { $in: ['libraryId1', 'libraryId2'] },
|
||||
removed: { $ne: true },
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
@@ -15,7 +15,7 @@
|
||||
"packages\\collection2\\collection2.js"
|
||||
]
|
||||
},
|
||||
"checkJs": true,
|
||||
"checkJs": false,
|
||||
"allowJs": true
|
||||
},
|
||||
"vueCompilerOptions": {
|
||||
|
||||
Reference in New Issue
Block a user