Hi,
I'm using TypeOrm, i'm executing a raw query, but the one of the date column is being returned as string, so TypeOrm or node is not converting it to UTC as it would if i call a query using TypeOrm methods or queryBuilder, what am i doing wrong here?
using PostgreSQL
async activeShift(userId: number, { date }: SingleDateQuery) {
const startDate = startOfDay(date);
const endDate = endOfDay(date);
const queryToExec = `
SELECT s.id, s.name,
(SELECT COALESCE(json_agg(json_build_object('created_at', a.created_at, 'type', a.type)), '[]')
FROM attendance a
WHERE a.shift_id = s.id
AND a.user_id = us.user_id
AND a.created_at BETWEEN :startDate AND :endDate) AS actions
FROM user_shift us
LEFT JOIN
shift s ON us.shift_id = s.id AND s.deleted_at IS NULL
LEFT JOIN
attendance a ON s.id = a.shift_id AND a.user_id = us.user_id AND us.deleted_at IS NULL
WHERE us.user_id = :userId
GROUP BY s.id, us.user_id, s.start_time
ORDER BY s.start_time;`;
const queryParams = { userId, startDate, endDate };
const { query, params } = convertToQueryWithParameters(queryToExec, queryParams);
return await this.userRepo.query(query, params);
}
// result
[
{
"id": 8,
"name": "Morning",
"actions": [
{
"created_at": "2023-10-12T22:12:53.986+05:30",
"type": "CHECK_IN"
}
]
},
{
"id": 9,
"name": "Night",
"actions": []
}
]
created_at us getting converted from 2023-10-12 16:42:53.986000 +00:00 to 2023-10-12T22:12:53.986+05:30, but not to the UTC without offset, like 2023-10-12T16:42:53.986Z.