Skip to content

Notification Schema#5

Open
emmanishikawa wants to merge 8 commits intomainfrom
notifications-schema
Open

Notification Schema#5
emmanishikawa wants to merge 8 commits intomainfrom
notifications-schema

Conversation

@emmanishikawa
Copy link
Collaborator

@emmanishikawa emmanishikawa commented Feb 10, 2026

Describe your changes

  • Created Notification Schema including id, type, labId, resourceId, recipients, and createdAt date.

Issue ticket number and link

https://docs.google.com/document/d/1cAICVmUirgPTL-fq3dkHVtx4QkyrG0XCJO7VUxnibdA/edit?usp=sharing

Checklist before requesting a review

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • This change requires a documentation update

@emmanishikawa emmanishikawa changed the title created notification schema Created notification schema Feb 10, 2026
@emmanishikawa emmanishikawa changed the title Created notification schema Notification Schema Feb 10, 2026
const { Schema } = mongoose;

const notificationSchema = new Schema({
_id: { type: String, required: true },
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: formatting properly would be a plus

fullDocument: "updateLookup",
});

console.log("[notifications] watcher started");
Copy link
Collaborator

Choose a reason for hiding this comment

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

might want to take this out when sending a PR to merge onto main

export async function startNotificationWatcher() {
await connectToDatabase();

const collection = mongoose.connection.collection("products");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this should be items instead of products. Products was the default file from the boilerplate.


const updatedDoc = change.fullDocument;
if (!updatedDoc) continue;

Copy link
Collaborator

Choose a reason for hiding this comment

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

We can add a comment here where we can check the quantity and compare it to the specified threshold. If it is less we continue else we will send a noti

Copy link
Collaborator

@arnavjk007 arnavjk007 left a comment

Choose a reason for hiding this comment

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

Just some minor changes

const { Schema } = mongoose;

const notificationSchema = new Schema({
_id: { type: String, required: true },
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can delete _id since it is an internal thing that MongoDB handles.

Comment on lines 6 to 10
type: { type: String, required: true },
labId: { type: String, required: true },
resourceId: { type: String, required: true },
recipients: {
type: [String],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shift labId to be the top field just so its consistent with the rest of the schemas

type: { type: String, required: true },
labId: { type: String, required: true },
resourceId: { type: String, required: true },
recipients: {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can also add a field in recipients called roles so we know who should be notified.

Copy link
Collaborator

@arnavjk007 arnavjk007 left a comment

Choose a reason for hiding this comment

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

Small comment change but everything else looks good

Comment on lines 21 to 25
/**
* Get the updated document from the change stream
* If quantity is below the threshold, continue
* else send a notification
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: can we separate these two comments into 1: what the code does now and 2: a reminder to implement the threshold checking here once other parts are implemented

Copy link
Collaborator

@arnavjk007 arnavjk007 left a comment

Choose a reason for hiding this comment

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

Small schema type change

resourceId: { type: String, required: true },
recipients: {
type: [String],
roles: { type: String },
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just noticed this but this should be a list of strings, not {}.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants