first commit
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
const MONGO_DB_URL = "mongo.lpaconsulting.fr"
|
||||
const CAPTCHA_ERROR_COLLECTION_PREFIX = "CAPTCHA_ERROR_"
|
||||
const BLACK_LIST = "BLACK_LIST"
|
||||
const DB_NAME = "appointment"
|
||||
const COLLECTION_NAME = "appointment"
|
||||
const ACCEPTED_APPOINTMENT_LIST = "ACCEPTED_APPOINTMENT_LIST"
|
||||
const EMAIL_LIST = "EMAIL_LIST"
|
||||
const DESTINATION_EMAIL_LIST = "DESTINATION_EMAIL_LIST"
|
||||
|
||||
|
||||
const mongoose = require("mongoose");
|
||||
mongoose.Promise = global.Promise;
|
||||
mongoose.connect(`mongodb://${MONGO_DB_URL}:27017/appointment`);
|
||||
|
||||
const {MongoClient} = require('mongodb');
|
||||
const ReserveResultPojo = require("../models/ReserveResultPojo");
|
||||
const ContactPojo = require("../models/ContactPojo");
|
||||
|
||||
function formatDate(date) {
|
||||
let d = new Date(date),
|
||||
month = '' + (d.getMonth() + 1),
|
||||
day = '' + d.getDate(),
|
||||
year = d.getFullYear();
|
||||
|
||||
if (month.length < 2)
|
||||
month = '0' + month;
|
||||
if (day.length < 2)
|
||||
day = '0' + day;
|
||||
|
||||
return [year, month, day].join('-');
|
||||
}
|
||||
|
||||
class MongoManager {
|
||||
constructor() {
|
||||
//init mongoDb
|
||||
let uri = `mongodb://appointment:Rdv%402022@${MONGO_DB_URL}/appointment`
|
||||
this.client = new MongoClient(uri)
|
||||
}
|
||||
|
||||
async connect() {
|
||||
await this.client.connect()
|
||||
this.db = this.client.db("appointment")
|
||||
}
|
||||
|
||||
async getAllSuccessfulItemsForDay(day) {
|
||||
return await this.db.collection(day).find().toArray()
|
||||
}
|
||||
|
||||
async saveReserveToDb(reservePojo) {
|
||||
let collectionName = formatDate(new Date())
|
||||
return await this.db.collection(collectionName).replaceOne({'_id': reservePojo.id,}, reservePojo, {upsert: true})
|
||||
}
|
||||
}
|
||||
|
||||
let manag = new MongoManager();
|
||||
(async () => {
|
||||
await manag.connect()
|
||||
// console.log(await manag.getAllSuccessfulItemsForDay('2022-09-06'))
|
||||
// let reserv = new ReserveResultPojo('U4S4RN', '753426925', '84838026', "gnautaurasa@hotmail.com", 'jingyi', 'DU', 1, 'https://rendezvousparis.hermes.com/client/register/U4S4RN');
|
||||
let contact = new ContactPojo('753426925', '84838026', 'DU', 'jingyi',
|
||||
"gnautaurasa@hotmail.com"
|
||||
);
|
||||
let reserv = ReserveResultPojo.create_from_contact(contact, 'U4S4RN', 'https://rendezvousparis.hermes.com/client/register/U4S4RN', 1)
|
||||
await manag.saveReserveToDb(reserv.to_mongo_dict());
|
||||
})()
|
||||
Reference in New Issue
Block a user