|
1 | 1 | // Returns a Mongo query filter that checks if the value of the given field is today |
2 | 2 | // Made fieldName variable in case we want to have different checks for `updatedAt`/`createdAt`/`deletedAt`/etc. |
3 | | -export function isToday(fieldName: string) { |
| 3 | +export function isToday(fieldName: string, timezone: string = 'UTC') { |
4 | 4 | const today = new Date(); |
5 | 5 | return { |
6 | | - $expr: { |
7 | | - $eq: [ |
| 6 | + $expr: { // Allows use of aggregation operators in queries |
| 7 | + $eq: [ // Checks equality between two values |
| 8 | + // Value 1: The field from the document |
8 | 9 | { |
9 | | - $dateToString: { format: '%Y-%m-%d', date: `$${fieldName}` } |
| 10 | + $dateToString: { format: '%Y-%m-%d', date: `$${fieldName}`, timezone } |
10 | 11 | }, |
11 | | - { $dateToString: { format: '%Y-%m-%d', date: today } } |
| 12 | + // Value 2: Today's date |
| 13 | + { $dateToString: { format: '%Y-%m-%d', date: today, timezone } } |
12 | 14 | ] |
13 | 15 | } |
14 | 16 | }; |
15 | 17 | } |
16 | 18 |
|
17 | | -export function hasSameLocation(locationObjectId: string) { |
| 19 | +export function hasSameLocation(locationObjectId: string): { locationObjectId: string } { |
18 | 20 | return { |
19 | | - locationObjectId: locationObjectId |
| 21 | + locationObjectId |
20 | 22 | }; |
21 | 23 | } |
22 | 24 |
|
23 | | -export function isSelf(userObjectId: string) { |
| 25 | +export function isSelf(userObjectId: string): { _id: string } { |
24 | 26 | return { |
25 | 27 | _id: userObjectId |
26 | 28 | }; |
27 | 29 | } |
28 | 30 |
|
29 | | -export function isCreatedBySelf(userObjectId: string) { |
| 31 | +export function isCreatedBySelf(userObjectId: string): { createdByUserObjectId: string } { |
30 | 32 | return { |
31 | 33 | createdByUserObjectId: userObjectId |
32 | 34 | }; |
33 | 35 | } |
34 | 36 |
|
35 | | -export function hasRole(roles: string[]) { |
| 37 | +export function hasRole(roles: string[]): { role: { $in: string[] } } { |
36 | 38 | return { |
37 | 39 | role: { $in: roles } |
38 | 40 | }; |
|
0 commit comments