@@ -211,6 +211,54 @@ export function applySorters(ast, sorters) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply Top Level Sub to the AST
|
||||||
|
* @param node
|
||||||
|
* @param fieldPath
|
||||||
|
* @param filterField
|
||||||
|
*/
|
||||||
|
function applyTopLevelSub(node, fieldPath, filterField) {
|
||||||
|
// Find or create the where argument for the top-level subfield
|
||||||
|
let whereArg = node.selectionSet.selections
|
||||||
|
.find(selection => selection.name.value === fieldPath[0])
|
||||||
|
?.arguments.find(arg => arg.name.value === 'where');
|
||||||
|
|
||||||
|
if (!whereArg) {
|
||||||
|
whereArg = {
|
||||||
|
kind: Kind.ARGUMENT,
|
||||||
|
name: {kind: Kind.NAME, value: 'where'},
|
||||||
|
value: {kind: Kind.OBJECT, fields: []},
|
||||||
|
};
|
||||||
|
const topLevelSubSelection = node.selectionSet.selections.find(selection =>
|
||||||
|
selection.name.value === fieldPath[0]
|
||||||
|
);
|
||||||
|
if (topLevelSubSelection) {
|
||||||
|
topLevelSubSelection.arguments = topLevelSubSelection.arguments || [];
|
||||||
|
topLevelSubSelection.arguments.push(whereArg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Correctly position the nested filter without an extra 'where'
|
||||||
|
if (fieldPath.length > 2) { // More than one level deep
|
||||||
|
let currentField = whereArg.value;
|
||||||
|
fieldPath.slice(1, -1).forEach((path, index) => {
|
||||||
|
let existingField = currentField.fields.find(f => f.name.value === path);
|
||||||
|
if (!existingField) {
|
||||||
|
existingField = {
|
||||||
|
kind: Kind.OBJECT_FIELD,
|
||||||
|
name: {kind: Kind.NAME, value: path},
|
||||||
|
value: {kind: Kind.OBJECT, fields: []}
|
||||||
|
};
|
||||||
|
currentField.fields.push(existingField);
|
||||||
|
}
|
||||||
|
currentField = existingField.value;
|
||||||
|
});
|
||||||
|
currentField.fields.push(filterField);
|
||||||
|
} else { // Directly under the top level
|
||||||
|
whereArg.value.fields.push(filterField);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply filters to the AST
|
* Apply filters to the AST
|
||||||
* @param ast
|
* @param ast
|
||||||
@@ -224,13 +272,18 @@ export function applyFilters(ast, filters) {
|
|||||||
filters.forEach(filter => {
|
filters.forEach(filter => {
|
||||||
const fieldPath = filter.field.split('.');
|
const fieldPath = filter.field.split('.');
|
||||||
let topLevel = false;
|
let topLevel = false;
|
||||||
|
let topLevelSub = false;
|
||||||
|
|
||||||
// Determine if the filter should be applied at the top level
|
// Determine if the filter should be applied at the top level
|
||||||
if (fieldPath[0].startsWith('[') && fieldPath[0].endsWith(']')) {
|
if (fieldPath.length === 2) {
|
||||||
fieldPath[0] = fieldPath[0].substring(1, fieldPath[0].length - 1); // Strip the brackets
|
|
||||||
topLevel = true;
|
topLevel = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( fieldPath.length > 2 && fieldPath[0].startsWith('[') && fieldPath[0].endsWith(']')) {
|
||||||
|
fieldPath[0] = fieldPath[0].substring(1, fieldPath[0].length - 1); // Strip the brackets
|
||||||
|
topLevelSub = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Construct the filter for a top-level application
|
// Construct the filter for a top-level application
|
||||||
const targetFieldName = fieldPath[fieldPath.length - 1];
|
const targetFieldName = fieldPath[fieldPath.length - 1];
|
||||||
|
|
||||||
@@ -239,6 +292,8 @@ export function applyFilters(ast, filters) {
|
|||||||
|
|
||||||
if (topLevel) {
|
if (topLevel) {
|
||||||
applyTopLevelFilter(node, fieldPath, filterField);
|
applyTopLevelFilter(node, fieldPath, filterField);
|
||||||
|
} else if (topLevelSub) {
|
||||||
|
applyTopLevelSub(node, fieldPath, filterField);
|
||||||
} else {
|
} else {
|
||||||
applyNestedFilter(node, fieldPath, filterField);
|
applyNestedFilter(node, fieldPath, filterField);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,7 +160,7 @@ exports.sendNotification = async (req, res) => {
|
|||||||
.send({
|
.send({
|
||||||
topic: "PRD_PATRICK-messaging",
|
topic: "PRD_PATRICK-messaging",
|
||||||
notification: {
|
notification: {
|
||||||
title: `ImEX Online Message - ,
|
title: `ImEX Online Message -` ,
|
||||||
body: "Test Noti.",
|
body: "Test Noti.",
|
||||||
//imageUrl: "https://thinkimex.com/img/io-fcm.png",
|
//imageUrl: "https://thinkimex.com/img/io-fcm.png",
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user