Skip to content

Commit

Permalink
Add archived: false to queries for users and orgs
Browse files Browse the repository at this point in the history
  • Loading branch information
richford committed Sep 11, 2024
1 parent dd9a07f commit 9568f1c
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 51 deletions.
9 changes: 8 additions & 1 deletion src/helpers/query/assignments.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,18 @@ export const getUsersByAssignmentIdRequestBody = ({
},
{
fieldFilter: {
field: { fieldPath: `assignments.assigned` },
field: { fieldPath: 'assignments.assigned' },
op: 'ARRAY_CONTAINS_ANY',
value: { arrayValue: { values: [{ stringValue: adminId }] } },
},
},
{
fieldFilter: {
field: { fieldPath: 'archived' },
op: 'EQUAL',
value: { booleanValue: false },
},
},
],
},
};
Expand Down
97 changes: 51 additions & 46 deletions src/helpers/query/orgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,77 +49,82 @@ export const getOrgsRequestBody = ({
},
];

requestBody.structuredQuery.where = {
compositeFilter: {
op: 'AND',
filters: [
{
fieldFilter: {
field: { fieldPath: 'archived' },
op: 'EQUAL',
value: { booleanValue: false },
},
},
],
},
};

if (orgName && !(parentDistrict || parentSchool)) {
requestBody.structuredQuery.where = {
requestBody.structuredQuery.where.compositeFilter.filters.push({
fieldFilter: {
field: { fieldPath: 'name' },
op: 'EQUAL',
value: { stringValue: orgName },
},
};
});
} else if (orgType === 'schools' && parentDistrict) {
if (orgName) {
requestBody.structuredQuery.where = {
compositeFilter: {
op: 'AND',
filters: [
{
fieldFilter: {
field: { fieldPath: 'name' },
op: 'EQUAL',
value: { stringValue: orgName },
},
},
{
fieldFilter: {
field: { fieldPath: 'districtId' },
op: 'EQUAL',
value: { stringValue: parentDistrict },
},
},
],
requestBody.structuredQuery.where.compositeFilter.filters.push(
{
fieldFilter: {
field: { fieldPath: 'name' },
op: 'EQUAL',
value: { stringValue: orgName },
},
},
};
{
fieldFilter: {
field: { fieldPath: 'districtId' },
op: 'EQUAL',
value: { stringValue: parentDistrict },
},
},
);
} else {
requestBody.structuredQuery.where = {
requestBody.structuredQuery.where.compositeFilter.filters.push({
fieldFilter: {
field: { fieldPath: 'districtId' },
op: 'EQUAL',
value: { stringValue: parentDistrict },
},
};
});
}
} else if (orgType === 'classes' && parentSchool) {
if (orgName) {
requestBody.structuredQuery.where = {
compositeFilter: {
op: 'AND',
filters: [
{
fieldFilter: {
field: { fieldPath: 'name' },
op: 'EQUAL',
value: { stringValue: orgName },
},
},
{
fieldFilter: {
field: { fieldPath: 'schoolId' },
op: 'EQUAL',
value: { stringValue: parentSchool },
},
},
],
requestBody.structuredQuery.where.compositeFilter.filters.push(
{
fieldFilter: {
field: { fieldPath: 'name' },
op: 'EQUAL',
value: { stringValue: orgName },
},
},
};
{
fieldFilter: {
field: { fieldPath: 'schoolId' },
op: 'EQUAL',
value: { stringValue: parentSchool },
},
},
);
} else {
requestBody.structuredQuery.where = {
requestBody.structuredQuery.where.compositeFilter.filters.push({
fieldFilter: {
field: { fieldPath: 'schoolId' },
op: 'EQUAL',
value: { stringValue: parentSchool },
},
};
});
}
}

Expand Down
23 changes: 19 additions & 4 deletions src/helpers/query/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,23 @@ export const getUsersRequestBody = ({
},
];

requestBody.structuredQuery.where = {
compositeFilter: {
op: 'AND',
filters: [
{
fieldFilter: {
field: { fieldPath: 'archived' },
op: 'EQUAL',
value: { booleanValue: false },
},
},
],
},
};

if (userIds.length > 0) {
requestBody.structuredQuery.where = {
requestBody.structuredQuery.where.compositeFilter.filters.push({
fieldFilter: {
field: { fieldPath: 'id' }, // change this to accept document Id, if we need
op: 'IN',
Expand All @@ -51,15 +66,15 @@ export const getUsersRequestBody = ({
},
},
},
};
});
} else if (orgType && orgId) {
requestBody.structuredQuery.where = {
requestBody.structuredQuery.where.compositeFilter.filters.push({
fieldFilter: {
field: { fieldPath: `${orgType}.current` }, // change this to accept document Id, if we need
op: 'ARRAY_CONTAINS',
value: { stringValue: orgId },
},
};
});
} else {
throw new Error('Must provide either userIds or orgType and orgId');
}
Expand Down

0 comments on commit 9568f1c

Please sign in to comment.