@better-giving/endowment 4.0.7 → 4.0.9
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 +4 -3
- package/dist/db.mjs +27 -3
- package/dist/schema.mjs +1 -1
- package/package.json +1 -1
- package/src/db.mts +40 -4
- 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, IMilestoneNew, 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";
|
|
@@ -109,8 +109,7 @@ export declare class NpoDb extends Db {
|
|
|
109
109
|
PK: string;
|
|
110
110
|
SK: string;
|
|
111
111
|
};
|
|
112
|
-
prog_milestone_record(prog: string, data:
|
|
113
|
-
id: string;
|
|
112
|
+
prog_milestone_record(prog: string, data: IMilestoneNew): {
|
|
114
113
|
date: string;
|
|
115
114
|
title: string;
|
|
116
115
|
description: string;
|
|
@@ -130,12 +129,14 @@ export declare class NpoDb extends Db {
|
|
|
130
129
|
};
|
|
131
130
|
npo_med_put(npo: number, url: string): Promise<string>;
|
|
132
131
|
npo_med(npo: number, mid: string): Promise<IMedia | undefined>;
|
|
132
|
+
npo_med_update(npo: number, prev: IMedia, update: IMediaUpdate): Promise<Record<string, any>>;
|
|
133
133
|
npo_med_delete(npo: number, mid: string): Promise<import("@aws-sdk/lib-dynamodb").DeleteCommandOutput>;
|
|
134
134
|
npo<T extends TNpoDbKeys[]>(id: string | number, fields?: T): Promise<TNpoDbProjectedTo<T> | undefined>;
|
|
135
135
|
npo_update_comps({ target, slug, social_media_urls, ...update }: INpoUpdate): UpdateComps;
|
|
136
136
|
npo_update(id: number, update: INpoUpdate): Promise<import("@aws-sdk/lib-dynamodb").UpdateCommandOutput>;
|
|
137
137
|
prog_milestones(id: string): Promise<IMilestone[]>;
|
|
138
138
|
prog_milestone_delete(pid: string, mid: string): Promise<import("@aws-sdk/lib-dynamodb").DeleteCommandOutput>;
|
|
139
|
+
prog_milestone_put(pid: string, content: IMilestoneNew): Promise<string>;
|
|
139
140
|
prog_milestone_update(pid: string, mid: string, update: IMilestoneUpdate): Promise<Record<string, any> | undefined>;
|
|
140
141
|
npo_program(id: string, npo_id: number): Promise<IProgram | undefined>;
|
|
141
142
|
npo_programs(id: number): Promise<IProgramDb[]>;
|
package/dist/db.mjs
CHANGED
|
@@ -148,8 +148,9 @@ export class NpoDb extends Db {
|
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
150
|
prog_milestone_record(prog, data) {
|
|
151
|
+
const mid = crypto.randomUUID();
|
|
151
152
|
return {
|
|
152
|
-
...this.key_prog_milestone(
|
|
153
|
+
...this.key_prog_milestone(mid, prog),
|
|
153
154
|
...data,
|
|
154
155
|
};
|
|
155
156
|
}
|
|
@@ -185,6 +186,21 @@ export class NpoDb extends Db {
|
|
|
185
186
|
const { Item: i } = await this.client.send(cmd);
|
|
186
187
|
return i && to_imedia(i);
|
|
187
188
|
}
|
|
189
|
+
async npo_med_update(npo, prev, update) {
|
|
190
|
+
const new_sk = med_sk(prev.id, prev.type, (update.featured ?? prev.featured) ? "0" : "1");
|
|
191
|
+
const cmd = new UpdateCommand({
|
|
192
|
+
TableName: NpoDb.name,
|
|
193
|
+
Key: this.key_npo_med(prev.id, npo),
|
|
194
|
+
UpdateExpression: "SET #url = :url, gsi1SK = :gsi1SK",
|
|
195
|
+
ExpressionAttributeNames: { "#url": "url" },
|
|
196
|
+
ExpressionAttributeValues: {
|
|
197
|
+
":url": update.url ?? prev.url,
|
|
198
|
+
":gsi1SK": new_sk,
|
|
199
|
+
},
|
|
200
|
+
ReturnValues: "ALL_NEW",
|
|
201
|
+
});
|
|
202
|
+
return this.client.send(cmd).then((res) => res.Attributes ?? {});
|
|
203
|
+
}
|
|
188
204
|
async npo_med_delete(npo, mid) {
|
|
189
205
|
const cmd = new DeleteCommand({
|
|
190
206
|
TableName: NpoDb.name,
|
|
@@ -274,6 +290,15 @@ export class NpoDb extends Db {
|
|
|
274
290
|
});
|
|
275
291
|
return this.client.send(cmd);
|
|
276
292
|
}
|
|
293
|
+
async prog_milestone_put(pid, content) {
|
|
294
|
+
const mid = crypto.randomUUID();
|
|
295
|
+
const item = this.prog_milestone_record(pid, content);
|
|
296
|
+
const cmd = new PutCommand({
|
|
297
|
+
TableName: NpoDb.name,
|
|
298
|
+
Item: item,
|
|
299
|
+
});
|
|
300
|
+
return this.client.send(cmd).then(() => mid);
|
|
301
|
+
}
|
|
277
302
|
async prog_milestone_update(pid, mid, update) {
|
|
278
303
|
const upd8 = new UpdateBuilder();
|
|
279
304
|
for (const [key, value] of Object.entries(update)) {
|
|
@@ -327,10 +352,9 @@ export class NpoDb extends Db {
|
|
|
327
352
|
Item: db_prog,
|
|
328
353
|
});
|
|
329
354
|
for (const m of milestones || []) {
|
|
330
|
-
const mid = crypto.randomUUID();
|
|
331
355
|
txs.put({
|
|
332
356
|
TableName: NpoDb.name,
|
|
333
|
-
Item: this.prog_milestone_record(pid,
|
|
357
|
+
Item: this.prog_milestone_record(pid, m),
|
|
334
358
|
});
|
|
335
359
|
}
|
|
336
360
|
const cmd = new TransactWriteCommand({
|
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,7 +23,9 @@ 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,
|
|
28
|
+
IMilestoneNew,
|
|
27
29
|
IMilestoneUpdate,
|
|
28
30
|
INpo,
|
|
29
31
|
INpoUpdate,
|
|
@@ -199,9 +201,10 @@ export class NpoDb extends Db {
|
|
|
199
201
|
};
|
|
200
202
|
}
|
|
201
203
|
|
|
202
|
-
prog_milestone_record(prog: string, data:
|
|
204
|
+
prog_milestone_record(prog: string, data: IMilestoneNew) {
|
|
205
|
+
const mid = crypto.randomUUID();
|
|
203
206
|
return {
|
|
204
|
-
...this.key_prog_milestone(
|
|
207
|
+
...this.key_prog_milestone(mid, prog),
|
|
205
208
|
...data,
|
|
206
209
|
};
|
|
207
210
|
}
|
|
@@ -244,6 +247,27 @@ export class NpoDb extends Db {
|
|
|
244
247
|
return i && to_imedia(i);
|
|
245
248
|
}
|
|
246
249
|
|
|
250
|
+
async npo_med_update(npo: number, prev: IMedia, update: IMediaUpdate) {
|
|
251
|
+
const new_sk = med_sk(
|
|
252
|
+
prev.id,
|
|
253
|
+
prev.type,
|
|
254
|
+
(update.featured ?? prev.featured) ? "0" : "1"
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
const cmd = new UpdateCommand({
|
|
258
|
+
TableName: NpoDb.name,
|
|
259
|
+
Key: this.key_npo_med(prev.id, npo),
|
|
260
|
+
UpdateExpression: "SET #url = :url, gsi1SK = :gsi1SK",
|
|
261
|
+
ExpressionAttributeNames: { "#url": "url" },
|
|
262
|
+
ExpressionAttributeValues: {
|
|
263
|
+
":url": update.url ?? prev.url,
|
|
264
|
+
":gsi1SK": new_sk,
|
|
265
|
+
},
|
|
266
|
+
ReturnValues: "ALL_NEW",
|
|
267
|
+
});
|
|
268
|
+
return this.client.send(cmd).then((res) => res.Attributes ?? {});
|
|
269
|
+
}
|
|
270
|
+
|
|
247
271
|
async npo_med_delete(npo: number, mid: string) {
|
|
248
272
|
const cmd = new DeleteCommand({
|
|
249
273
|
TableName: NpoDb.name,
|
|
@@ -348,6 +372,19 @@ export class NpoDb extends Db {
|
|
|
348
372
|
});
|
|
349
373
|
return this.client.send(cmd);
|
|
350
374
|
}
|
|
375
|
+
async prog_milestone_put(
|
|
376
|
+
pid: string,
|
|
377
|
+
content: IMilestoneNew
|
|
378
|
+
): Promise<string> {
|
|
379
|
+
const mid = crypto.randomUUID();
|
|
380
|
+
const item = this.prog_milestone_record(pid, content);
|
|
381
|
+
const cmd = new PutCommand({
|
|
382
|
+
TableName: NpoDb.name,
|
|
383
|
+
Item: item,
|
|
384
|
+
});
|
|
385
|
+
return this.client.send(cmd).then(() => mid);
|
|
386
|
+
}
|
|
387
|
+
|
|
351
388
|
async prog_milestone_update(
|
|
352
389
|
pid: string,
|
|
353
390
|
mid: string,
|
|
@@ -412,10 +449,9 @@ export class NpoDb extends Db {
|
|
|
412
449
|
});
|
|
413
450
|
|
|
414
451
|
for (const m of milestones || []) {
|
|
415
|
-
const mid = crypto.randomUUID();
|
|
416
452
|
txs.put({
|
|
417
453
|
TableName: NpoDb.name,
|
|
418
|
-
Item: this.prog_milestone_record(pid,
|
|
454
|
+
Item: this.prog_milestone_record(pid, m),
|
|
419
455
|
});
|
|
420
456
|
}
|
|
421
457
|
|