Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kit assembly now enforces uppercase and checks for matching ID numbers #642

Merged
merged 1 commit into from
Sep 10, 2024
Merged
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
25 changes: 25 additions & 0 deletions utils/firestore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2298,8 +2298,32 @@ const getNotificationSpecByCategoryAndAttempt = async (category = "", attempt =
return snapshot.empty ? null : snapshot.docs[0].data();
};

const validateKitAssemblyData = (data) => {
// Ensure that values are uppercase and that the appropriate values match
if(data[fieldMapping.returnKitId]) {
data[fieldMapping.returnKitId] = ('' + data[fieldMapping.returnKitId]).toUpperCase();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of adding the empty strings in all these statements?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do it to make 100% sure it's a string before running toUpperCase, in case we end up with a number.

}
if(data[fieldMapping.supplyKitId]) {
data[fieldMapping.supplyKitId] = ('' + data[fieldMapping.supplyKitId]).toUpperCase();
}
if(data[fieldMapping.collectionCupId]) {
data[fieldMapping.collectionCupId] = ('' + data[fieldMapping.collectionCupId]).toUpperCase();
}
if(data[fieldMapping.collectionCardId]) {
data[fieldMapping.collectionCardId] = ('' + data[fieldMapping.collectionCardId]).toUpperCase();
}
if(data[fieldMapping.returnKitId] !== data[fieldMapping.supplyKitId]) {
throw new Error('Return Kit ID and Supply Kit ID do not match.');
}
if(data[fieldMapping.collectionCupId] !== data[fieldMapping.collectionCardId]) {
throw new Error('Collection Cup ID and Collection Card ID do not match.');
}
return data;
}

const addKitAssemblyData = async (data) => {
try {
validateKitAssemblyData(data);
await db.collection('kitAssembly').add(data);
return true;
}
Expand All @@ -2312,6 +2336,7 @@ const addKitAssemblyData = async (data) => {

const updateKitAssemblyData = async (data) => {
try {
validateKitAssemblyData(data);
const snapshot = await db.collection('kitAssembly').where('687158491', '==', data['687158491']).get();
printDocsCount(snapshot, "updateKitAssemblyData");

Expand Down