0.0.1 • Published 7 months ago

unsubscribe v0.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

#Unsubscribe This is a class that provides methods for unsubscribing contacts from a mailing list and storing the data in MongoDB.

Installation To use this class, you need to install the mongodb module from npm:

Usage To create an instance of the Unsubscribe class, you need to pass the MongoDB connection string and the database name as arguments:

npm install unsubscribe@latest

const unsubscribe = new Unsubscribe( "mongodb://localhost:27017", "myDatabase" );

The Unsubscribe class has the following methods:

storeSubscription(criteria: any, subscription: any): This method takes two arguments: criteria and subscription. The criteria argument is an object that specifies the query criteria for finding the document to update in the contacts collection. The subscription argument is a boolean value that indicates whether the contact is unsubscribed or not. This method updates the document with the subscription status and the date of the action. getMongoClient(): This method returns a MongoDB client object that is connected to the database. If the client is already connected, it returns the existing client. Otherwise, it creates a new client and connects to the database using the connection string provided in the constructor. updateMongoCollection(collectionName: any, criteria: any, document: any, dbName: any): This method takes four arguments: collectionName, criteria, document, and dbName. The collectionName argument is a string that specifies the name of the collection to update. The criteria argument is an object that specifies the query criteria for finding the document to update. The document argument is an object that specifies the fields and values to update in the document. The dbName argument is an optional string that specifies the name of the database to use. If not provided, it uses the database name provided in the constructor. This method updates the document using the MongoDB client returned by the getMongoClient() method. Example Here is an example of how to use the Unsubscribe class to unsubscribe a contact:

const unsubscribe = new Unsubscribe( "mongodb://localhost:27017", "myDatabase" );

// Assume we have a contact document with this structure: // { // _id: "123456789", // name: "John Doe", // email: "johndoe@example.com", // isUnsubscribed: false, // subscribedDate: "2023-10-24T07:34:53.000Z" // }

// To unsubscribe this contact, we can use this code: unsubscribe.storeSubscription( { _id: "123456789" }, // criteria true // subscription );

// This will update the document with these fields: // { // _id: "123456789", // name: "John Doe", // email: "johndoe@example.com", // isUnsubscribed: true, // unsubscribedDate: "2023-10-24T07:35:53.000Z" // current date // }

0.0.1

7 months ago