I am creating a hostel booking API, i am still figuring it out bit by bit.
Currently there are different room types and they have a quantity, when a room is booked(it has a check-in and check-out date) the quantity drops by 1, how do i go about the logic for adding +1 to that room type when the check-out date has passed. Any help is greatly appreciated.
I am using the Express framework and the Sequelize ORM.
Related
I am currently developing an appointment calendar with React and NodeJS using the Google Calendar API. The goal is to archive the following:
Step 1: User selects the desired Date in Calendar (done)
Step 2: Show Free 30 Minutes Timeslots in between the opening hours (done)
Step 3: Book Appointment and add to Calendar (done)
But now the problem is, that each timeslot can have 10 individual bookings and I want to show how much is left (e.g 3 People booked the slot at 15:30, I want to show that there are 7 Slots left) Currently if one booked the 15:30 slot it is removed. That is because I use a FreeBusy Query, and this only shows me the busy time not how many events there are.
My first thought was to save the bookings also in a database and then look for every timeslot how many people booked before, but this seems like not the best solution.
Do you have any better ideas on how to solve this problem?
Thanks in advance
Just a suggestion but maybe for each of the event placed on the calendar you could attach an extended property to mark the event as booked.
"extendedProperties": {
"shared": {
"booked": "false",}
}
https://developers.google.com/calendar/v3/reference/events#resource
Then whenever someone books an event, you could mark that event as booked by changing the extended property mentioned. To display the amount of event that are free to book you could filter the list of events by timeMin, timeMax of the selected Timeslot and count the number of events that are marked free or booked.
I keep getting this error when executing a transaction on rate object id's that were created a few days ago.
{
"source": "USPS",
"code": "",
"text": "The selected shipment date must be within 7 days of 02/15/2017, 07:11PM CST."
}
Im integrating shippo with my Node.js web application. I am using shippo node.js library.
shippo.shipment.create({, function(err, shipment) {});
I built a basic store. When user gets to checkout section, I get rates from shippo. I display those rates to the user. The user chooses which rate he wants. I save the rate object id to a database.
shippo.transaction.create({, function(err, transaction) {});
I fulfill the order and print the shipping label. The application goes to the database and retrieves rate object id to execute the transaction with shippo. In return Im suppose to get a tracking # and label information, but instead I get the error.
I first thought that the rate object id only last 7 days and then expires on its own or something. When I checked the rate object id:
https://api.goshippo.com/rates/2a0b50cbc5184362a0ea2385b490bc7b
It shows object was created 2/18. Today is the 2/21. So that cant be. The error says "The selected shipment date must be within 7 days of 02/15/2017, 07:11PM CST."
What does it mean? Why did I get it?
It seems to only happen to rate object id's that were create 2+ days ago. If the rate object id was created yesterday, I could still execute the transaction no problem.
screenshot
It looks like you are using a rate from the past (not the same day) that is causing this error to occur.
When you make a shipment at the /shipments/ endpoint, you are able to specify the submission_date when creating the shipment. If you do not specify the submission_date (you would generally only do this if you know the day you plan on shipping the item out), Shippo automatically sets the submission_date to the date the request is being made.
The reason that you are getting an error, is that you're using a rate for a shipment that has a submission_date in the past. Some carriers will only permit a submission date that is the current date, or some date in the future.
You can find more details here on the shipment object that might help.
I'm fairly new to Mongo, and the documentation is still a little blurry for my understanding.
I'm working on a pharmacy app - where doctors are connected to practices. (medical practice) The details (name, address, etc.) of these practices can be changed at any given time, and so I cannot create the doctor in this format:
{ name: "Dr. John", practice: "Yellow Medical Centre" } - because if that name is changed, it will be a pain updating it everywhere.
Now, my question is, assuming that I am already inserting doctors with a practice_id field instead of a practice_name field - how do I resolve the practice_id into a practice_name, before sending it back to the client - because they would like to see the doctor's practice name, not the ID of it.
(I made a huge mess, initially, so I'll just leave the plain part here)
app.get('/doctors', function(req,res){
db.doctors.find().forEach(function(err,doc){
});
});
Am I supposed to loop through them all, or not? Mt goal is for each Doctor's->practice_id to actually contain practice_name - which obviously requires the assistence of the db.practices collection. But how do I make that translation in this stage? Or am I supposed to do it from the client-side controller?
Some guidance would be helpful, thanks.
After a new Customer Refund record is saved (After Submit user event) I need to communicate with an external web service and then update 2 fields in the record. When this code is executed to load the Customer Refund
var o = nlapiLoadRecord("customerrefund", 1906);
This error message is returned:
INVALID_TRANS_TYP
Transaction type specified is incorrect.
I found a list of supported records in the "Chapter 60 SuiteScript Supported Records" of SuiteScript Developer & Reference Guide which says the Customer Refund is only available in a server side script.
How should I go about updating the Customer Refund record?
Without seeing more code, it looks ok. I would double check that the internalId of 1906 is correct.
Also, if you're just submitting two fields, I would use nlapiSubmitField(), this will take less governance points and be quicker for NetSuite rather than nlapiLoadRecord / nlapiSubmitRecord.
Your code looks correct, if you are updating the current record I would recommend using below code to avoid incorrect internalid:
var o = nlapiLoadRecord("customerrefund", nlapiGetRecordId());
Also, I would recommend that if you need to update the fields, consider using before submit user event script on customer refund and you can update the fields using nlapiSetFieldValue(FIELD_ID, FIELD_VALUE). No need to submit the record in case of before submit.
If your script is deployed in the customer refund record, you can also do nlapiGetRecordType().
I'm doing a notification system for my website.
A notification systeme like facebook. Or stackoverflow.
I have 2 problems.
How store in db ? I can store ALL notifications in the user document ? or in a document apart (because i think monogdb is limited for size in a document ?) Or, store intelligently ? (using inc, or a value (see: true/false) in db, with query sophisticated)
How do for brought at the page ? For exemple, when i click in a link in my inbox for stackoverflow, i'm redirect to the page. But me, i have a system that is multipage for exemple: I have 100 friends. There are listed 30 per page. So when i click on the notification i can't redirect to the because it's impossible to know the good page (users can be removed).
Thank you very much !
And if you have another ideas, tell me. Thanks.
EDIT:
(sorry for my english, i'm french)
For the first problem, i realize that i have to wait the time comes to choose my structure. Because my notification is .. a little complicated, so advance to the feeling.
For the second, i solved the problem. I explain:
(I take the exemple of friends because it's easy to undestand.)
I stored my data like this:
{
friends: [
{_id: xxxxx, ts: xxxx},
{_id: xxxxx, ts: xxxx}
]
}
Imagine i display all friends: 30 per page.
The problems are:
when i want to display all friends i cant sort using mongo. (a little problem)
If i want to lead a user to this list (30 per page) at a special friend, always keeping the sort by ts. I can't know the page. The uniq solution is to take all document.
But: veryyy bad in performance.
So, i store like this:
{
friends: {
xxxx: {ts:xxx},
xxxx: {ts:xxx}
}
}
Know i can sort the document, with use skip and limit.
So if i want a portion, i do not need to take all documents.
To know the page, i just do the number of < or > to the ts, i have for exemple 11 friends who are > to the ts of the friends that i want, and do a count for all friends (ex: 50 friends) with 50 and 11, i can guess the page.
Is this solution is good ?
- i need a count
- a query to know the number of > or <
and i can take the page where is listed the friend, keeping the sort ts
You can don't understand why i use a count. I need because they are not store in the same docment.
2 EDIT:
The problem with this solution, is that i need to make query object and update object outside of the mongo query (ex: for do friends.xxxxxx: {$exists:true}
ps: And what advantages are to use ts instead of date for mongodb ?
I'm using ts but i think i will store date, and no ts.
3 EDIT
I will do like Sammaye. Store in separate document. Take a look at: http://mongly.com/Multiple-Collections-Versus-Embedded-Documents/#1 and http://openmymind.net/2012/1/30/MongoDB-Embedded-Documents-vs-Multiple-Collections/
#Stennie make a pretty complete answer.
However recently I did a similar thing in PHP for my website. The first thing to understand is whether you are doing a notification system or a wall (the two are very different), it seems unclear to me and I am not sure what you mean by:
How do for brought at the page ? For exemple, when i click in a link
in my inbox for stackoverflow, i'm redirect to the page. But me, i
have a system that is multipage for exemple: I have 100 friends. There
are listed 30 per page. So when i click on the notification i can't
redirect to the because it's impossible to know the good page (users
can be removed).
That is not very good English and is very confusing when I read it. If you can expand on that I am sure people can answer better.
For a notification system I found that a large collection of notification objects also worked. So I had a schema like:
{
_id: {},
to_user: ObjectId{},
user_id: ObjectId{}, // Originating user
custom_text: "has posted a new comment on your wall post",
read: false,
ts: MongoDate()
}
And this would literally be the document I have to produce notifications. Each time a user commits an action that generates a notification it writes a new row to the DB with to_user being populated each time with each user needing to be notified. As for multiple users commiting the same action I actually convert the user_id field in a list of OjbectId's so I can say:
Sam, Dan and Mike all commented on your wall post
I then query by ts storing the last ts that the user looked at in their row allowing me to do a range based query on the newest notifications each time. This works quite well for sharding and querying in my personal experience.
Hope it helps,
Whether to embed or link is a common question for data modelling in MongoDB. If your number of notifications is going to be unbounded, you are likely going to be better saving these in a separate collection.
The current 16Mb document limit actually isn't as much as an issue as some other considerations:
A performance issue you may encounter by including all notifications in a single document is that fast-growing documents may also need to be relocated in the database more frequently (see Padding Factor).
You may want to be applying multiple updates to a document (such as setting a "read" flag on notifications) in a very short period of time, which means more contention for updating the same document (see Atomic Operations).
In order to implement paging you can use limit() in combination with a range query or skip(). A range query (eg. based on an indexed notificationDate) will make more effective use of indexes and perform better than skip() as your collection grows.