Skip to content

Commit 1fad054

Browse files
Add shouldMakeActive param
1 parent be1b812 commit 1fad054

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/get-web-push-certificate-insert-serial-operations.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ export async function getWebPushCertificateInsertSerialOperations(
4949
webPushCertificate,
5050
containValue,
5151
containerLinkId,
52+
shouldMakeActive = false
5253
} = param;
53-
const { containLinkId, webPushCertificateLinkId } = await getReservedLinkIds();
54-
const { containTypeLinkId, webPushCertificateTypeLinkId } = await getTypeLinkIds();
54+
const { containLinkId, webPushCertificateLinkId , usesWebPushCertificateLinkId} = await getReservedLinkIds();
55+
const { containTypeLinkId, webPushCertificateTypeLinkId, usesWebPushCertificateTypeLinkId } = await getTypeLinkIds();
5556
const serialOperations = [];
5657
const webPushCertificateInsertSerialOperation = createSerialOperation({
5758
type: 'insert',
@@ -93,6 +94,19 @@ export async function getWebPushCertificateInsertSerialOperations(
9394
serialOperations.push(valueOfContainInsertSerialOperation);
9495
}
9596

97+
if(shouldMakeActive) {
98+
const usesWebPushCertificateInsertSerialOperation = createSerialOperation({
99+
type: 'insert',
100+
table: 'links',
101+
objects: {
102+
id: usesWebPushCertificateLinkId,
103+
type_id: usesWebPushCertificateTypeLinkId,
104+
from_id: deep.linkId,
105+
to_id: webPushCertificateLinkId,
106+
},
107+
})
108+
}
109+
96110
return serialOperations;
97111

98112
type GetReservedLinkIdsResult = Required<
@@ -106,6 +120,7 @@ export async function getWebPushCertificateInsertSerialOperations(
106120
let result: GetReservedLinkIdsResult = {
107121
containLinkId: 0,
108122
webPushCertificateLinkId: 0,
123+
usesWebPushCertificateLinkId: 0
109124
};
110125
const linksToReserveCount =
111126
Object.keys(result).length -
@@ -117,6 +132,8 @@ export async function getWebPushCertificateInsertSerialOperations(
117132
param.reservedLinkIds?.containLinkId ?? reservedLinkIds.pop()!,
118133
webPushCertificateLinkId:
119134
param.reservedLinkIds?.webPushCertificateLinkId ?? reservedLinkIds.pop()!,
135+
usesWebPushCertificateLinkId:
136+
param.reservedLinkIds?.usesWebPushCertificateLinkId ?? reservedLinkIds.pop()!,
120137
};
121138
return result;
122139
}
@@ -133,6 +150,9 @@ export async function getWebPushCertificateInsertSerialOperations(
133150
webPushCertificateTypeLinkId:
134151
param.typeLinkIds?.webPushCertificateTypeLinkId ||
135152
(await deep.id(PACKAGE_NAME, LinkName[LinkName.WebPushCertificate])),
153+
usesWebPushCertificateTypeLinkId:
154+
param.typeLinkIds?.usesWebPushCertificateTypeLinkId ||
155+
(await deep.id(PACKAGE_NAME, LinkName[LinkName.UsesWebPushCertificate])),
136156
};
137157
return result;
138158
}
@@ -151,6 +171,10 @@ export interface GetWebPushCertificateInsertSerialOperationsParam {
151171
* Reserved link id for the contain
152172
*/
153173
containLinkId?: number;
174+
/**
175+
* Reserved link id for the usesWebPushCertificate
176+
*/
177+
usesWebPushCertificateLinkId?: number;
154178
};
155179
/**
156180
* Link ids of types that will be used in the serial operations
@@ -164,6 +188,10 @@ export interface GetWebPushCertificateInsertSerialOperationsParam {
164188
* Link id of the webPushCertificate type
165189
*/
166190
webPushCertificateTypeLinkId?: number;
191+
/**
192+
* Link id of the usesWebPushCertificate type
193+
*/
194+
usesWebPushCertificateTypeLinkId?: number;
167195
};
168196
/**
169197
* Deep Client
@@ -188,4 +216,10 @@ export interface GetWebPushCertificateInsertSerialOperationsParam {
188216
* If {@link GetWebPushCertificateInsertSerialOperationsParam.containerLinkId} is null, this will be ignored
189217
*/
190218
containValue?: string | undefined;
219+
/**
220+
* If true, the link will be made active by creating a {@link LinkName.UsesServiceAccount} link pointing to it
221+
*
222+
* @defaultValue false
223+
*/
224+
shouldMakeActive?: boolean;
191225
}

0 commit comments

Comments
 (0)