Skip to content

Commit

Permalink
WIP: query users by archived status
Browse files Browse the repository at this point in the history
  • Loading branch information
richford committed Sep 11, 2024
1 parent 489bb74 commit 2730a69
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 119 deletions.
42 changes: 42 additions & 0 deletions firebase/admin/firestore.indexes.json
Original file line number Diff line number Diff line change
Expand Up @@ -3030,6 +3030,20 @@
}
]
},
{
"collectionGroup": "classes",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "districtId",
"order": "ASCENDING"
},
{
"fieldPath": "lastRoarSync",
"order": "ASCENDING"
}
]
},
{
"collectionGroup": "districts",
"queryScope": "COLLECTION",
Expand Down Expand Up @@ -3180,6 +3194,20 @@
}
]
},
{
"collectionGroup": "schools",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "districtId",
"order": "ASCENDING"
},
{
"fieldPath": "lastRoarSync",
"order": "ASCENDING"
}
]
},
{
"collectionGroup": "users",
"queryScope": "COLLECTION",
Expand Down Expand Up @@ -3426,6 +3454,20 @@
}
]
},
{
"collectionGroup": "users",
"queryScope": "COLLECTION",
"fields": [
{
"fieldPath": "districts.current",
"arrayConfig": "CONTAINS"
},
{
"fieldPath": "archived",
"order": "ASCENDING"
}
]
},
{
"collectionGroup": "users",
"queryScope": "COLLECTION",
Expand Down
6 changes: 6 additions & 0 deletions src/components/ListUsers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ const columns = ref([
dataType: 'string',
sort: false,
},
{
field: 'archived',
header: 'Archived',
dataType: 'boolean',
sort: false,
},
{
header: 'Edit',
button: true,
Expand Down
91 changes: 0 additions & 91 deletions src/helpers/query/assignments.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,97 +173,6 @@ export const getAssignmentsRequestBody = ({
return requestBody;
};

export const getUsersByAssignmentIdRequestBody = ({
adminId,
orgType,
orgId,
filter,
aggregationQuery,
pageLimit,
page,
paginate = true,
select = userSelectFields,
}) => {
const requestBody = {
structuredQuery: {},
};

if (!aggregationQuery) {
if (paginate) {
requestBody.structuredQuery.limit = pageLimit;
requestBody.structuredQuery.offset = page * pageLimit;
}

if (select.length > 0) {
requestBody.structuredQuery.select = {
fields: select.map((field) => ({ fieldPath: field })),
};
}
}

requestBody.structuredQuery.from = [
{
collectionId: 'users',
allDescendants: false,
},
];

requestBody.structuredQuery.where = {
compositeFilter: {
op: 'AND',
filters: [
{
fieldFilter: {
field: { fieldPath: `${pluralizeFirestoreCollection(orgType)}.current` },
op: 'ARRAY_CONTAINS',
value: { stringValue: orgId },
},
},
{
fieldFilter: {
field: { fieldPath: 'assignments.assigned' },
op: 'ARRAY_CONTAINS_ANY',
value: { arrayValue: { values: [{ stringValue: adminId }] } },
},
},
{
fieldFilter: {
field: { fieldPath: 'archived' },
op: 'EQUAL',
value: { booleanValue: false },
},
},
],
},
};

if (filter) {
requestBody.structuredQuery.where.compositeFilter.filters.push({
fieldFilter: {
field: { fieldPath: filter[0].field },
op: 'EQUAL',
value: { stringValue: filter[0].value },
},
});
}

if (aggregationQuery) {
return {
structuredAggregationQuery: {
...requestBody,
aggregations: [
{
alias: 'count',
count: {},
},
],
},
};
}

return requestBody;
};

export const getFilteredScoresRequestBody = ({
adminId,
orgId,
Expand Down
43 changes: 17 additions & 26 deletions src/helpers/query/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const getUsersRequestBody = ({
paginate = true,
select = ['name'],
orderBy,
restrictToActiveUsers = false,
}) => {
const requestBody = {
structuredQuery: {},
Expand Down Expand Up @@ -39,18 +40,20 @@ export const getUsersRequestBody = ({
requestBody.structuredQuery.where = {
compositeFilter: {
op: 'AND',
filters: [
{
fieldFilter: {
field: { fieldPath: 'archived' },
op: 'EQUAL',
value: { booleanValue: false },
},
},
],
filters: [],
},
};

if (restrictToActiveUsers) {
requestBody.structuredQuery.where.compositeFilter.filters.push({
fieldFilter: {
field: { fieldPath: 'archived' },
op: 'EQUAL',
value: { booleanValue: false },
},
});
}

if (userIds.length > 0) {
requestBody.structuredQuery.where.compositeFilter.filters.push({
fieldFilter: {
Expand Down Expand Up @@ -96,21 +99,7 @@ export const getUsersRequestBody = ({
return requestBody;
};

export const usersPageFetcher = async (userIds, pageLimit, page) => {
const axiosInstance = getAxiosInstance();
const requestBody = getUsersRequestBody({
userIds,
aggregationQuery: false,
pageLimit: pageLimit.value,
page: page.value,
paginate: true,
});

console.log(`Fetching page ${page.value} for ${userIds}`);
return axiosInstance.post(':runQuery', requestBody).then(({ data }) => mapFields(data));
};

export const fetchUsersByOrg = async (orgType, orgId, pageLimit, page, orderBy) => {
export const fetchUsersByOrg = async (orgType, orgId, pageLimit, page, orderBy, restrictToActiveUsers = false) => {
const axiosInstance = getAxiosInstance();
const requestBody = getUsersRequestBody({
orgType,
Expand All @@ -119,22 +108,24 @@ export const fetchUsersByOrg = async (orgType, orgId, pageLimit, page, orderBy)
pageLimit: pageLimit.value,
page: page.value,
paginate: true,
select: ['username', 'name', 'studentData', 'userType'],
select: ['username', 'name', 'studentData', 'userType', 'archived'],
orderBy: orderBy.value,
restrictToActiveUsers: restrictToActiveUsers,
});

console.log(`Fetching users page ${page.value} for ${orgType} ${orgId}`);
return axiosInstance.post(':runQuery', requestBody).then(({ data }) => mapFields(data));
};

export const countUsersByOrg = async (orgType, orgId, orderBy) => {
export const countUsersByOrg = async (orgType, orgId, orderBy, restrictToActiveUsers = false) => {
const axiosInstance = getAxiosInstance();
const requestBody = getUsersRequestBody({
orgType,
orgId,
aggregationQuery: true,
paginate: false,
orderBy: orderBy.value,
restrictToActiveUsers: restrictToActiveUsers,
});

return axiosInstance.post(':runAggregationQuery', requestBody).then(({ data }) => {
Expand Down
3 changes: 1 addition & 2 deletions src/pages/SignIn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ const modalPassword = ref('');
const authWithClever = () => {
console.log('---> authWithClever');
authStore.signInWithCleverRedirect();
authStore.signInWithCleverPopup();
spinner.value = true;
// }
};
Expand All @@ -225,7 +225,6 @@ const authWithClassLink = () => {
spinner.value = true;
} else {
authStore.signInWithClassLinkRedirect();
// authStore.signInWithCleverPopup();
spinner.value = true;
}
};
Expand Down

0 comments on commit 2730a69

Please sign in to comment.