@better-giving/endowment 4.0.7 → 4.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/db.d.mts +2 -1
- package/dist/db.mjs +15 -0
- package/dist/schema.mjs +1 -1
- package/package.json +1 -1
- package/src/db.mts +22 -0
- package/src/schema.mts +1 -1
package/dist/db.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Db, type UpdateComps } from "@better-giving/db";
|
|
2
2
|
import type { IMedia, IMediaPage, INpoReferredBy, INpoWithRegNum, INpoWithRid, TBinFlag, TNpoDbKeys, TNpoDbProjectedTo } from "./interfaces.mjs";
|
|
3
|
-
import type { IMediaSearchObj, IMilestone, IMilestoneUpdate, INpo, INpoUpdate, IProgram, IProgramDb, IProgramNew, IProgramUpdate, TMediaType } from "./schema.mjs";
|
|
3
|
+
import type { IMediaSearchObj, IMediaUpdate, IMilestone, IMilestoneUpdate, INpo, INpoUpdate, IProgram, IProgramDb, IProgramNew, IProgramUpdate, TMediaType } from "./schema.mjs";
|
|
4
4
|
export declare class NpoDb extends Db {
|
|
5
5
|
static readonly name = "endowments_v3";
|
|
6
6
|
static readonly slug_env_gsi: "slug-env-gsi";
|
|
@@ -130,6 +130,7 @@ export declare class NpoDb extends Db {
|
|
|
130
130
|
};
|
|
131
131
|
npo_med_put(npo: number, url: string): Promise<string>;
|
|
132
132
|
npo_med(npo: number, mid: string): Promise<IMedia | undefined>;
|
|
133
|
+
npo_med_update(npo: number, prev: IMedia, update: IMediaUpdate): Promise<Record<string, any>>;
|
|
133
134
|
npo_med_delete(npo: number, mid: string): Promise<import("@aws-sdk/lib-dynamodb").DeleteCommandOutput>;
|
|
134
135
|
npo<T extends TNpoDbKeys[]>(id: string | number, fields?: T): Promise<TNpoDbProjectedTo<T> | undefined>;
|
|
135
136
|
npo_update_comps({ target, slug, social_media_urls, ...update }: INpoUpdate): UpdateComps;
|
package/dist/db.mjs
CHANGED
|
@@ -185,6 +185,21 @@ export class NpoDb extends Db {
|
|
|
185
185
|
const { Item: i } = await this.client.send(cmd);
|
|
186
186
|
return i && to_imedia(i);
|
|
187
187
|
}
|
|
188
|
+
async npo_med_update(npo, prev, update) {
|
|
189
|
+
const new_sk = med_sk(prev.id, prev.type, (update.featured ?? prev.featured) ? "0" : "1");
|
|
190
|
+
const cmd = new UpdateCommand({
|
|
191
|
+
TableName: NpoDb.name,
|
|
192
|
+
Key: this.key_npo_med(prev.id, npo),
|
|
193
|
+
UpdateExpression: "SET #url = :url, gsi1SK = :gsi1SK",
|
|
194
|
+
ExpressionAttributeNames: { "#url": "url" },
|
|
195
|
+
ExpressionAttributeValues: {
|
|
196
|
+
":url": update.url ?? prev.url,
|
|
197
|
+
":gsi1SK": new_sk,
|
|
198
|
+
},
|
|
199
|
+
ReturnValues: "ALL_NEW",
|
|
200
|
+
});
|
|
201
|
+
return this.client.send(cmd).then((res) => res.Attributes ?? {});
|
|
202
|
+
}
|
|
188
203
|
async npo_med_delete(npo, mid) {
|
|
189
204
|
const cmd = new DeleteCommand({
|
|
190
205
|
TableName: NpoDb.name,
|
package/dist/schema.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $, $req, $req_num_gt0, donate_method_id, env, https_url, int_gte1,
|
|
1
|
+
import { $, $int_gte1, $req, $req_num_gt0, donate_method_id, env, https_url, int_gte1, org_designation, slug, unsdg_num, } from "@better-giving/schemas";
|
|
2
2
|
export { $, $req, $req_num_gt0, donate_method_id, env, https_url, int_gte1, $int_gte1, org_designation, slug, unsdg_num, } from "@better-giving/schemas";
|
|
3
3
|
import * as v from "valibot";
|
|
4
4
|
export const min_payout_amount = 50;
|
package/package.json
CHANGED
package/src/db.mts
CHANGED
|
@@ -23,6 +23,7 @@ import { med_key_filter, med_sk, to_imedia } from "./media.mjs";
|
|
|
23
23
|
import { projection } from "./npo.mjs";
|
|
24
24
|
import type {
|
|
25
25
|
IMediaSearchObj,
|
|
26
|
+
IMediaUpdate,
|
|
26
27
|
IMilestone,
|
|
27
28
|
IMilestoneUpdate,
|
|
28
29
|
INpo,
|
|
@@ -244,6 +245,27 @@ export class NpoDb extends Db {
|
|
|
244
245
|
return i && to_imedia(i);
|
|
245
246
|
}
|
|
246
247
|
|
|
248
|
+
async npo_med_update(npo: number, prev: IMedia, update: IMediaUpdate) {
|
|
249
|
+
const new_sk = med_sk(
|
|
250
|
+
prev.id,
|
|
251
|
+
prev.type,
|
|
252
|
+
(update.featured ?? prev.featured) ? "0" : "1"
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
const cmd = new UpdateCommand({
|
|
256
|
+
TableName: NpoDb.name,
|
|
257
|
+
Key: this.key_npo_med(prev.id, npo),
|
|
258
|
+
UpdateExpression: "SET #url = :url, gsi1SK = :gsi1SK",
|
|
259
|
+
ExpressionAttributeNames: { "#url": "url" },
|
|
260
|
+
ExpressionAttributeValues: {
|
|
261
|
+
":url": update.url ?? prev.url,
|
|
262
|
+
":gsi1SK": new_sk,
|
|
263
|
+
},
|
|
264
|
+
ReturnValues: "ALL_NEW",
|
|
265
|
+
});
|
|
266
|
+
return this.client.send(cmd).then((res) => res.Attributes ?? {});
|
|
267
|
+
}
|
|
268
|
+
|
|
247
269
|
async npo_med_delete(npo: number, mid: string) {
|
|
248
270
|
const cmd = new DeleteCommand({
|
|
249
271
|
TableName: NpoDb.name,
|