-
Notifications
You must be signed in to change notification settings - Fork 1
/
get-push-notification.ts
79 lines (73 loc) · 2.12 KB
/
get-push-notification.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { DeepClient } from '@deep-foundation/deeplinks/imports/client.js';
import { PushNotification } from './push-notification.js';
import { Package } from './package.js';
/**
* Gets push notification from deep
*
* @throws {Error} If title is not found
* @throws {Error} If body is not found
*
* @example
```ts
const pushNotification = await getPushNotification({
deep,
pushNotificationLinkId,
})
```
*/
export async function getPushNotification({
deep,
pushNotificationLinkId,
}: GetPushNotificationParam): Promise<GetPushNotificationResult> {
const $package = new Package({ deep });
// const titleTypeLinkId = await $package.PushNotificationTitle.id();
// const bodyTypeLinkId = await $package.PushNotificationBody.id();
// const pushNotificationTreeLinkId = await $package.PushNotificationTree.id();
// const { data: linksDownToParentPushNotificationMp } = await deep.select(
// {
// up: {
// parent_id: { _eq: pushNotificationLinkId },
// tree_id: { _eq: pushNotificationTreeLinkId },
// },
// },
// {
// returning: `${deep.selectReturning}
// to {
// ${deep.selectReturning}
// }
// `,
// }
// );
// const linkWithTitle = linksDownToParentPushNotificationMp.find(
// (link) => link.type_id === titleTypeLinkId
// );
// if (!linkWithTitle) {
// throw new Error(`A link with type ##${titleTypeLinkId} is not found`);
// }
// const linkWithBody = linksDownToParentPushNotificationMp.find(
// (link) => link.type_id === bodyTypeLinkId
// );
// if (!linkWithBody) {
// throw new Error(`A link with type ##${bodyTypeLinkId} is not found`);
// }
// return {
// title: linkWithTitle?.to.value.value,
// body: linkWithBody.to.value.value,
// };
const {data: [link]} = await deep.select(pushNotificationLinkId);
return {
title: link.value.value.title,
body: link.value.value.body,
}
}
export interface GetPushNotificationParam {
/**
* Deep Client
*/
deep: DeepClient;
/**
* Link id of push notification
*/
pushNotificationLinkId: number;
}
export type GetPushNotificationResult = PushNotification;