I have a controller to make a room which needs a JsonBody in order to add the room:
{
"roomName": "Sol",
"properties": "Geluidsdichte kamer",
"capacity": 40,
"buildingName": "16A",
"location": "Leuven",
"reservableDates": ["2022-12-03", "2022-12-04", "2022-12-05"],
"imageUrl":"www"
}
Here we find a reservableDates object which is just a list of dates when the room is available for reservation
Now the backend code to put this code into the database isn't relevant for my problem so I will not state this here.
However the output I get in my database is this...
select * from rooms inner join rooms_reservable_dates
on room_id = rooms_room_id;
Now I have another function in my backend so I can update a room (For example change its available reservable dates, but the problem is that I don't know how to write the query so I can change the reservable dates while also updating the roomName for example.
I'm using JpaRepository in SpringBoot so I have to make a custom query for this.
In Postgresql I have 2 tables Rooms (with all the properties found in the picture except for the reservable_dates) and the other table is rooms_reservable_dates (which has the roomId and the dates that the room is available.
Thank you very much
Related
I have 2 tables contractPoint and contractPointHistory
ContractPointHistory
ContractPoint
I would like to get contractPoint where point will be subtracted by pointChange. For example: ContractPoint -> id: 3, point: 5
ContractPointHistory has contractPointId: 3 and pointChange: -5. So after manipulating point in contractPoint should be 0
I wrote this code, but it works just for getRawMany(), not for getMany()
const contractPoints = await getRepository(ContractPoint).createQueryBuilder('contractPoint')
.addSelect('"contractPoint".point + COALESCE((SELECT SUM(cpHistory.point_change) FROM contract_point_history AS cpHistory WHERE cpHistory.contract_point_id = contractPoint.id), 0) AS points')
.andWhere('EXTRACT(YEAR FROM contractPoint.validFrom) = :year', { year })
.andWhere('contractPoint.contractId = :contractId', { contractId })
.orderBy('contractPoint.grantedAt', OrderByDirection.Desc)
.getMany();
The method getMany can be used to select all attributes of an entity. However, if one wants to select some specific attributes of an entity then one needs to use getRawMany.
As per the documentation -
There are two types of results you can get using select query builder:
entities or raw results. Most of the time, you need to select real
entities from your database, for example, users. For this purpose, you
use getOne and getMany. But sometimes you need to select some specific
data, let's say the sum of all user photos. This data is not an
entity, it's called raw data. To get raw data, you use getRawOne and
getRawMany
From this, we can conclude that the query which you want to generate can not be made using getMany method.
How to retrieve multiple customer bookings customer data from MS Graph?
MS Graph is the API to access MS Bookings. I am attempting to retrieve customer information, which works for bookings with single customers. However you can have multiple customers.
API Documentation
Here are the api calls for a single customer, to access bookings.
1 Get User Token
https://login.microsoftonline.com/{{TenantID}}/oauth2/v2.0/token
2 Get List of Bookings for date period
https://graph.microsoft.com/beta/bookingBusinesses/{{BookingBusinessId}}/appointments
3 Get Booking with ID
https://graph.microsoft.com/beta/bookingBusinesses/{{BookingBusinessId}}/appointments/{{BookingId}}
The response object for a single customer booking, will include the following for customer information in the json object. However the multiple, will provide null. Pls Note, I have blanked out most values and represented this with a leading and ending "_".
Single customer booking
"id": "_bookid_",
"selfServiceAppointmentId": "_selfserviceappId_",
"additionalInformation": "",
"isLocationOnline": true,
"onlineMeetingUrl": "_teamsbookingid_",
"customerId": "_CustomerId_",
"customerName": "_customerName_",
"customerEmailAddress": "_email_",
"customerPhone": "_phone_",
"customerNotes": "_notes_",
Multiple customer booking
"id": "[bookid]",
"selfServiceAppointmentId": "[selfserviceappId]",
"additionalInformation": "",
"isLocationOnline": false,
"onlineMeetingUrl": null,
"customerId": null,
"customerName": null,
"customerEmailAddress": null,
"customerPhone": null,
"customerNotes": null,
The Calendar view delta object will instead of listing the customer details, will add the following note.
"NOTE: This is a Multi customer booking. Log into Bookings to see customer information and notes for this event."
Has anyone been able to solve multi customer bookings with MS Graph to retrieve customer data?
I have a container within CosmosDB that houses items. I am needing to find out the count of how many records I have within my container with the conditions of: Source and Date
This is a sample JSON schema in which each of my records/items holds. Each record has a unique id and acts as a single count.
{
"id": "1111111111122222222233333333",
"feedback": {
"Source": "test"
"Date": "1980-10-15T00:04:34Z",
"Ser": "test",
"Count_Of_Comments": "1",
"Count_Of_Votes": "1"
}
The container within CosmosDB looks like something like this:
Goal:
**I wish to return, the numb*er of id records (or the count) based on the Source and the Date.
This is what I have tried (below), however this does not seem to work and I am wondering if I am missing something here. Any help or suggestions are appreciated.
SELECT VALUE COUNT(c.id), c.Source, c.Date
FROM C
Where Source == "test", AND Date == "1980-10-15T00:04:34Z"
As David comments,there are some syntax errors.Please try this sql:
SELECT value COUNT(c.id) FROM c Where c.feedback.Source = "test" AND c.feedback.Date = "1980-10-15T00:04:34Z"
If you need Source and Date,you can try this:
SELECT COUNT(c.id) AS Count,max(c.feedback.Source) as Source,max(c.feedback.Date) as Date
FROM c
Where c.feedback.Source = "test" AND c.feedback.Date = "1980-10-15T00:04:34Z"
By the way,both COUNT(c.id) AND COUNT(1) can achieve your goal in your situation.More detail about SQL Query,you can refer to this documentation.
Hope this can help you.
I have logic querying a MSSQL Server database view and I've been searching for a solutions along with trying different techniques. Of course I don't expect a full solution where this is two parts (query builder & frontend javascript/chart) but any helpful direction would greatly appreciated. Here I'm getting the count of Leads on a particular day grouped by the date created and source of the leads. I'm trying build this the Laravel way so to speak, and display in charts.js. I'm thinking I might need to make two different database calls/queries. One count and one for the group by source text.
Thank you for your help for a solutions or an helpful direction I can take.
I have already done total leads for another chart but this project has some extra sugar to it.
SELECT count([LeadID]) as numleads,[LeadSource],cast(leadcreated as date) as
`enter code here`createddate
FROM [myDatabase].[dbo].[viewAllLeads]
where companyid=001
group by cast(leadcreated as date),[LeadSource]
order by createddate
Chart.js set up:
- Top links (horizontal) the groupby info by LeadSource
- Left, y-axis - the count of the leads
- Bottom x-axis - the date lead was created
It should actually be straight forward, but you need to be aware that using DB::raw() is necessary. To begin with, here your query a little bit nicer formatted:
SELECT
[LeadSource],
CAST([leadcreated] as date) as createddate,
COUNT([LeadID]) as numleads
FROM [dbo].[viewAllLeads]
WHERE [companyid] = '001'
GROUP BY [LeadSource], CAST([leadcreated] as date)
ORDER BY [createddate]
And converted to an Eloquent query:
DB::table('viewAllLeads') // the query builder doesn't care if it's a table or view
->select([
'LeadSource',
DB::raw('CAST(leadcreated as date) as createddate'),
DB::raw('COUNT(LeadID) as numleads')
])
->where('companyid', '001')
->groupBy('LeadSource', DB::raw('CAST(leadcreated as date)'))
->orderBy('createddate')
->get();
This will return a Illuminate\Support\Collection containing stdClass objects of the following form:
object(stdClass)#1 (3) {
["LeadSource"] => string(3) "ABC"
["createddate"] => string(10) "2019-08-05"
["numleads"] => int(15)
}
$leads = Lead::where('companyid', $companyid)->get()->groupBy(function ($item) {
return $item->created_at->format('Y-m-d');
})->sortBy(function ($item) {
return $item->created_at->format('x');
});
if you use dd($leads) you can see the data structure.
I am not the best at UML/database diagrams but the following hopefully shows my DB design (MsSQL)
I have a "Location" table with zero to many pallets assiociated with it (there are 0-many pallets IN a location). However that location can be one of two types, location x or y. This diagram simplifies it, but there are many different types of location, and very different fields for each type.
I am using Sequelize as an ORM, and trying to figure out how to do a particular query. I think I am close but quite stuck.
What I need is:
Select a single LocationTypeX where "active" is true, and where its corresponding Location has less than 10 pallets in it.
Previously I have gone and got all LocationTypeX where "active" is true. Included Location and Pallet (on location) and did it all in code to figure out which location is relavent. however that is taking forever, as there are thousands of Locations and loads of pallets spread out through them.
All I am after is to show the Location Name. That is it. But the Location name of one that matches the above condition. Hopefully someone can help?
So far I have
models.Location.findAll({
group: ['Location.id', 'Pallets.id'],
attributes: ['Location.id', 'Pallets.id', [models.sequelize.fn('COUNT',models.sequelize.col('Pallets.id')), 'PalletCount']],
include: [{
model: models.Pallet,
attributes: []
}]
}).then((ret)=> {
console.log(ret);
});
But this doesn't do the "active" check. And also doesn't do the where clause on the amount of pallets. Back to square one
I have managed to answer my own question with raw SQL that I can use in Sequelize. However I would still be interested to know how to do it in Sequelize
models.sequelize.query(
`SELECT TOP 1 Locations.id, Locations.name FROM LocationTypeX
INNER JOIN Locations ON LocationTypeX.LocationId = Locations.id
LEFT JOIN Pallets on (Locations.id = Pallets.LocationId)
WHERE LocationTypeX.active = 1
GROUP BY Locations.id, Locations.name
HAVING COUNT(Pallets.id) < 3`
, { type: models.sequelize.QueryTypes.SELECT})