@better-giving/endowment 4.0.14 → 4.0.16
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 +1 -1
- package/dist/db.mjs +29 -28
- package/package.json +1 -1
- package/src/db.mts +29 -28
package/dist/db.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import { Db, type UpdateComps } from "@better-giving/db";
|
|
|
2
2
|
import type { IMedia, IMediaPage, INpoReferredBy, INpoWithRegNum, INpoWithRid, TBinFlag, TNpoDbKeys, TNpoDbProjectedTo } from "./interfaces.mjs";
|
|
3
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
|
-
static readonly
|
|
5
|
+
static readonly table = "endowments_v3";
|
|
6
6
|
static readonly slug_env_gsi: "slug-env-gsi";
|
|
7
7
|
static readonly regnum_env_gsi: "regnum-env-gsi";
|
|
8
8
|
key_npo(id: number): {
|
package/dist/db.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import KSUID from "ksuid";
|
|
|
4
4
|
import { med_key_filter, med_sk, to_imedia } from "./media.mjs";
|
|
5
5
|
import { projection } from "./npo.mjs";
|
|
6
6
|
export class NpoDb extends Db {
|
|
7
|
-
static
|
|
7
|
+
static table = "endowments_v3";
|
|
8
8
|
static slug_env_gsi = "slug-env-gsi";
|
|
9
9
|
static regnum_env_gsi = "regnum-env-gsi";
|
|
10
10
|
key_npo(id) {
|
|
@@ -57,21 +57,22 @@ export class NpoDb extends Db {
|
|
|
57
57
|
}
|
|
58
58
|
async npos_get(ids, fields) {
|
|
59
59
|
const { names, expression } = projection(fields);
|
|
60
|
-
const
|
|
60
|
+
const cmd = new BatchGetCommand({
|
|
61
61
|
RequestItems: {
|
|
62
|
-
[NpoDb.
|
|
62
|
+
[NpoDb.table]: {
|
|
63
63
|
Keys: ids.map((id) => this.key_npo(id)),
|
|
64
64
|
ProjectionExpression: expression,
|
|
65
65
|
ExpressionAttributeNames: names,
|
|
66
66
|
},
|
|
67
67
|
},
|
|
68
68
|
});
|
|
69
|
-
const { Responses } = await this.client.send(
|
|
70
|
-
|
|
69
|
+
const { Responses } = await this.client.send(cmd);
|
|
70
|
+
const x = Responses?.[NpoDb.table] ?? [];
|
|
71
|
+
return x.map((i) => this.sans_keys(i));
|
|
71
72
|
}
|
|
72
73
|
async npo_count_inc() {
|
|
73
74
|
const cmd = new UpdateCommand({
|
|
74
|
-
TableName: NpoDb.
|
|
75
|
+
TableName: NpoDb.table,
|
|
75
76
|
Key: this.key_count,
|
|
76
77
|
UpdateExpression: "SET #count = #count + :one",
|
|
77
78
|
ExpressionAttributeNames: {
|
|
@@ -87,7 +88,7 @@ export class NpoDb extends Db {
|
|
|
87
88
|
const PK = this.key_npo_med("ksuid-sk", npo).PK;
|
|
88
89
|
const [expression, values] = med_key_filter(PK, opts);
|
|
89
90
|
const cmd = new QueryCommand({
|
|
90
|
-
TableName: NpoDb.
|
|
91
|
+
TableName: NpoDb.table,
|
|
91
92
|
IndexName: "gsi1",
|
|
92
93
|
Limit: opts.limit,
|
|
93
94
|
KeyConditionExpression: expression,
|
|
@@ -100,7 +101,7 @@ export class NpoDb extends Db {
|
|
|
100
101
|
}
|
|
101
102
|
async npo_referred_by(id) {
|
|
102
103
|
const cmd = new QueryCommand({
|
|
103
|
-
TableName: NpoDb.
|
|
104
|
+
TableName: NpoDb.table,
|
|
104
105
|
IndexName: "gsi1",
|
|
105
106
|
KeyConditionExpression: "#pk = :pk",
|
|
106
107
|
ExpressionAttributeValues: {
|
|
@@ -113,7 +114,7 @@ export class NpoDb extends Db {
|
|
|
113
114
|
}
|
|
114
115
|
async npo_with_rid(id) {
|
|
115
116
|
const cmd = new QueryCommand({
|
|
116
|
-
TableName: NpoDb.
|
|
117
|
+
TableName: NpoDb.table,
|
|
117
118
|
IndexName: "gsi2",
|
|
118
119
|
KeyConditionExpression: "gsi2PK = :pk",
|
|
119
120
|
ExpressionAttributeValues: {
|
|
@@ -127,7 +128,7 @@ export class NpoDb extends Db {
|
|
|
127
128
|
}
|
|
128
129
|
async npo_with_regnum(regnum, country = "United States") {
|
|
129
130
|
const cmd = new QueryCommand({
|
|
130
|
-
TableName: NpoDb.
|
|
131
|
+
TableName: NpoDb.table,
|
|
131
132
|
IndexName: NpoDb.regnum_env_gsi,
|
|
132
133
|
Limit: 1,
|
|
133
134
|
KeyConditionExpression: "#rn = :rn AND #env = :env",
|
|
@@ -187,7 +188,7 @@ export class NpoDb extends Db {
|
|
|
187
188
|
featured: false,
|
|
188
189
|
});
|
|
189
190
|
const command = new PutCommand({
|
|
190
|
-
TableName: NpoDb.
|
|
191
|
+
TableName: NpoDb.table,
|
|
191
192
|
Item: item,
|
|
192
193
|
});
|
|
193
194
|
await this.client.send(command);
|
|
@@ -195,7 +196,7 @@ export class NpoDb extends Db {
|
|
|
195
196
|
}
|
|
196
197
|
async npo_med(npo, mid) {
|
|
197
198
|
const cmd = new GetCommand({
|
|
198
|
-
TableName: NpoDb.
|
|
199
|
+
TableName: NpoDb.table,
|
|
199
200
|
Key: this.key_npo_med(mid, npo),
|
|
200
201
|
});
|
|
201
202
|
const { Item: i } = await this.client.send(cmd);
|
|
@@ -204,7 +205,7 @@ export class NpoDb extends Db {
|
|
|
204
205
|
async npo_med_update(npo, prev, update) {
|
|
205
206
|
const new_sk = med_sk(prev.id, prev.type, (update.featured ?? prev.featured) ? "0" : "1");
|
|
206
207
|
const cmd = new UpdateCommand({
|
|
207
|
-
TableName: NpoDb.
|
|
208
|
+
TableName: NpoDb.table,
|
|
208
209
|
Key: this.key_npo_med(prev.id, npo),
|
|
209
210
|
UpdateExpression: "SET #url = :url, gsi1SK = :gsi1SK",
|
|
210
211
|
ExpressionAttributeNames: { "#url": "url" },
|
|
@@ -218,7 +219,7 @@ export class NpoDb extends Db {
|
|
|
218
219
|
}
|
|
219
220
|
async npo_med_delete(npo, mid) {
|
|
220
221
|
const cmd = new DeleteCommand({
|
|
221
|
-
TableName: NpoDb.
|
|
222
|
+
TableName: NpoDb.table,
|
|
222
223
|
Key: this.key_npo_med(mid, npo),
|
|
223
224
|
});
|
|
224
225
|
return this.client.send(cmd);
|
|
@@ -227,7 +228,7 @@ export class NpoDb extends Db {
|
|
|
227
228
|
const { names, expression } = projection(fields);
|
|
228
229
|
if (typeof id === "string") {
|
|
229
230
|
const cmd = new QueryCommand({
|
|
230
|
-
TableName: NpoDb.
|
|
231
|
+
TableName: NpoDb.table,
|
|
231
232
|
IndexName: NpoDb.slug_env_gsi,
|
|
232
233
|
KeyConditionExpression: "#slug = :slug and #env = :env",
|
|
233
234
|
ExpressionAttributeValues: {
|
|
@@ -245,7 +246,7 @@ export class NpoDb extends Db {
|
|
|
245
246
|
return x ? this.sans_keys(x) : undefined;
|
|
246
247
|
}
|
|
247
248
|
const cmd = new GetCommand({
|
|
248
|
-
TableName: NpoDb.
|
|
249
|
+
TableName: NpoDb.table,
|
|
249
250
|
Key: this.key_npo(id),
|
|
250
251
|
ProjectionExpression: expression,
|
|
251
252
|
ExpressionAttributeNames: names,
|
|
@@ -279,7 +280,7 @@ export class NpoDb extends Db {
|
|
|
279
280
|
async npo_update(id, update) {
|
|
280
281
|
const upd8 = this.npo_update_comps(update);
|
|
281
282
|
const cmd = new UpdateCommand({
|
|
282
|
-
TableName: NpoDb.
|
|
283
|
+
TableName: NpoDb.table,
|
|
283
284
|
Key: this.key_npo(id),
|
|
284
285
|
...upd8,
|
|
285
286
|
ReturnValues: "ALL_NEW",
|
|
@@ -288,7 +289,7 @@ export class NpoDb extends Db {
|
|
|
288
289
|
}
|
|
289
290
|
async prog_milestones(id) {
|
|
290
291
|
const command = new QueryCommand({
|
|
291
|
-
TableName: NpoDb.
|
|
292
|
+
TableName: NpoDb.table,
|
|
292
293
|
KeyConditionExpression: `PK = :PK`,
|
|
293
294
|
ExpressionAttributeValues: {
|
|
294
295
|
":PK": this.key_prog_milestone("not-used", id).PK,
|
|
@@ -300,7 +301,7 @@ export class NpoDb extends Db {
|
|
|
300
301
|
}
|
|
301
302
|
async prog_milestone_delete(pid, mid) {
|
|
302
303
|
const cmd = new DeleteCommand({
|
|
303
|
-
TableName: NpoDb.
|
|
304
|
+
TableName: NpoDb.table,
|
|
304
305
|
Key: this.key_prog_milestone(mid, pid),
|
|
305
306
|
});
|
|
306
307
|
return this.client.send(cmd);
|
|
@@ -308,7 +309,7 @@ export class NpoDb extends Db {
|
|
|
308
309
|
async prog_milestone_put(pid, content) {
|
|
309
310
|
const item = this.prog_milestone_record(pid, content);
|
|
310
311
|
const cmd = new PutCommand({
|
|
311
|
-
TableName: NpoDb.
|
|
312
|
+
TableName: NpoDb.table,
|
|
312
313
|
Item: item,
|
|
313
314
|
});
|
|
314
315
|
return this.client.send(cmd).then(() => item.id);
|
|
@@ -319,7 +320,7 @@ export class NpoDb extends Db {
|
|
|
319
320
|
upd8.set(key, value);
|
|
320
321
|
}
|
|
321
322
|
const cmd = new UpdateCommand({
|
|
322
|
-
TableName: NpoDb.
|
|
323
|
+
TableName: NpoDb.table,
|
|
323
324
|
Key: this.key_prog_milestone(mid, pid),
|
|
324
325
|
...upd8.collect(),
|
|
325
326
|
ReturnValues: "ALL_NEW",
|
|
@@ -328,7 +329,7 @@ export class NpoDb extends Db {
|
|
|
328
329
|
}
|
|
329
330
|
async npo_program(id, npo_id) {
|
|
330
331
|
const cmd = new GetCommand({
|
|
331
|
-
TableName: NpoDb.
|
|
332
|
+
TableName: NpoDb.table,
|
|
332
333
|
Key: this.key_npo_program(id, npo_id),
|
|
333
334
|
});
|
|
334
335
|
const { Item: p } = await this.client.send(cmd);
|
|
@@ -342,7 +343,7 @@ export class NpoDb extends Db {
|
|
|
342
343
|
}
|
|
343
344
|
async npo_programs(id) {
|
|
344
345
|
const cmd = new QueryCommand({
|
|
345
|
-
TableName: NpoDb.
|
|
346
|
+
TableName: NpoDb.table,
|
|
346
347
|
KeyConditionExpression: `PK = :PK and begins_with(SK, :SK)`,
|
|
347
348
|
ExpressionAttributeValues: {
|
|
348
349
|
":PK": this.key_npo_program("not-used", id).PK,
|
|
@@ -362,12 +363,12 @@ export class NpoDb extends Db {
|
|
|
362
363
|
totalDonations: 0,
|
|
363
364
|
});
|
|
364
365
|
txs.put({
|
|
365
|
-
TableName: NpoDb.
|
|
366
|
+
TableName: NpoDb.table,
|
|
366
367
|
Item: db_prog,
|
|
367
368
|
});
|
|
368
369
|
for (const m of milestones || []) {
|
|
369
370
|
txs.put({
|
|
370
|
-
TableName: NpoDb.
|
|
371
|
+
TableName: NpoDb.table,
|
|
371
372
|
Item: this.prog_milestone_record(pid, m),
|
|
372
373
|
});
|
|
373
374
|
}
|
|
@@ -381,12 +382,12 @@ export class NpoDb extends Db {
|
|
|
381
382
|
const milestones = await this.prog_milestones(prog);
|
|
382
383
|
const txs = new Txs();
|
|
383
384
|
txs.del({
|
|
384
|
-
TableName: NpoDb.
|
|
385
|
+
TableName: NpoDb.table,
|
|
385
386
|
Key: this.key_npo_program(prog, npo),
|
|
386
387
|
});
|
|
387
388
|
for (const m of milestones) {
|
|
388
389
|
txs.del({
|
|
389
|
-
TableName: NpoDb.
|
|
390
|
+
TableName: NpoDb.table,
|
|
390
391
|
Key: this.key_prog_milestone(m.id, prog),
|
|
391
392
|
});
|
|
392
393
|
}
|
|
@@ -401,7 +402,7 @@ export class NpoDb extends Db {
|
|
|
401
402
|
upd8.set(key, value);
|
|
402
403
|
}
|
|
403
404
|
const cmd = new UpdateCommand({
|
|
404
|
-
TableName: NpoDb.
|
|
405
|
+
TableName: NpoDb.table,
|
|
405
406
|
Key: this.key_npo_program(prog, npo),
|
|
406
407
|
...upd8.collect(),
|
|
407
408
|
ReturnValues: "ALL_NEW",
|
package/package.json
CHANGED
package/src/db.mts
CHANGED
|
@@ -38,7 +38,7 @@ import type {
|
|
|
38
38
|
} from "./schema.mjs";
|
|
39
39
|
|
|
40
40
|
export class NpoDb extends Db {
|
|
41
|
-
static
|
|
41
|
+
static readonly table = "endowments_v3";
|
|
42
42
|
static readonly slug_env_gsi = "slug-env-gsi" as const;
|
|
43
43
|
static readonly regnum_env_gsi = "regnum-env-gsi" as const;
|
|
44
44
|
key_npo(id: number) {
|
|
@@ -100,22 +100,23 @@ export class NpoDb extends Db {
|
|
|
100
100
|
fields?: T
|
|
101
101
|
): Promise<TNpoDbProjectedTo<T>[]> {
|
|
102
102
|
const { names, expression } = projection(fields);
|
|
103
|
-
const
|
|
103
|
+
const cmd = new BatchGetCommand({
|
|
104
104
|
RequestItems: {
|
|
105
|
-
[NpoDb.
|
|
105
|
+
[NpoDb.table]: {
|
|
106
106
|
Keys: ids.map((id) => this.key_npo(id)),
|
|
107
107
|
ProjectionExpression: expression,
|
|
108
108
|
ExpressionAttributeNames: names,
|
|
109
109
|
},
|
|
110
110
|
},
|
|
111
111
|
});
|
|
112
|
-
const { Responses } = await this.client.send(
|
|
113
|
-
|
|
112
|
+
const { Responses } = await this.client.send(cmd);
|
|
113
|
+
const x = Responses?.[NpoDb.table] ?? [];
|
|
114
|
+
return x.map((i) => this.sans_keys(i));
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
async npo_count_inc(): Promise<number> {
|
|
117
118
|
const cmd = new UpdateCommand({
|
|
118
|
-
TableName: NpoDb.
|
|
119
|
+
TableName: NpoDb.table,
|
|
119
120
|
Key: this.key_count,
|
|
120
121
|
UpdateExpression: "SET #count = #count + :one",
|
|
121
122
|
ExpressionAttributeNames: {
|
|
@@ -134,7 +135,7 @@ export class NpoDb extends Db {
|
|
|
134
135
|
const [expression, values] = med_key_filter(PK, opts);
|
|
135
136
|
|
|
136
137
|
const cmd = new QueryCommand({
|
|
137
|
-
TableName: NpoDb.
|
|
138
|
+
TableName: NpoDb.table,
|
|
138
139
|
IndexName: "gsi1",
|
|
139
140
|
Limit: opts.limit,
|
|
140
141
|
KeyConditionExpression: expression,
|
|
@@ -149,7 +150,7 @@ export class NpoDb extends Db {
|
|
|
149
150
|
|
|
150
151
|
async npo_referred_by(id: string): Promise<INpoReferredBy[]> {
|
|
151
152
|
const cmd = new QueryCommand({
|
|
152
|
-
TableName: NpoDb.
|
|
153
|
+
TableName: NpoDb.table,
|
|
153
154
|
IndexName: "gsi1",
|
|
154
155
|
KeyConditionExpression: "#pk = :pk",
|
|
155
156
|
ExpressionAttributeValues: {
|
|
@@ -163,7 +164,7 @@ export class NpoDb extends Db {
|
|
|
163
164
|
|
|
164
165
|
async npo_with_rid(id: string): Promise<INpoWithRid | undefined> {
|
|
165
166
|
const cmd = new QueryCommand({
|
|
166
|
-
TableName: NpoDb.
|
|
167
|
+
TableName: NpoDb.table,
|
|
167
168
|
IndexName: "gsi2",
|
|
168
169
|
KeyConditionExpression: "gsi2PK = :pk",
|
|
169
170
|
ExpressionAttributeValues: {
|
|
@@ -181,7 +182,7 @@ export class NpoDb extends Db {
|
|
|
181
182
|
country = "United States"
|
|
182
183
|
): Promise<INpoWithRegNum | undefined> {
|
|
183
184
|
const cmd = new QueryCommand({
|
|
184
|
-
TableName: NpoDb.
|
|
185
|
+
TableName: NpoDb.table,
|
|
185
186
|
IndexName: NpoDb.regnum_env_gsi,
|
|
186
187
|
Limit: 1,
|
|
187
188
|
KeyConditionExpression: "#rn = :rn AND #env = :env",
|
|
@@ -251,7 +252,7 @@ export class NpoDb extends Db {
|
|
|
251
252
|
featured: false,
|
|
252
253
|
});
|
|
253
254
|
const command = new PutCommand({
|
|
254
|
-
TableName: NpoDb.
|
|
255
|
+
TableName: NpoDb.table,
|
|
255
256
|
Item: item,
|
|
256
257
|
});
|
|
257
258
|
await this.client.send(command);
|
|
@@ -260,7 +261,7 @@ export class NpoDb extends Db {
|
|
|
260
261
|
|
|
261
262
|
async npo_med(npo: number, mid: string): Promise<IMedia | undefined> {
|
|
262
263
|
const cmd = new GetCommand({
|
|
263
|
-
TableName: NpoDb.
|
|
264
|
+
TableName: NpoDb.table,
|
|
264
265
|
Key: this.key_npo_med(mid, npo),
|
|
265
266
|
});
|
|
266
267
|
const { Item: i } = await this.client.send(cmd);
|
|
@@ -275,7 +276,7 @@ export class NpoDb extends Db {
|
|
|
275
276
|
);
|
|
276
277
|
|
|
277
278
|
const cmd = new UpdateCommand({
|
|
278
|
-
TableName: NpoDb.
|
|
279
|
+
TableName: NpoDb.table,
|
|
279
280
|
Key: this.key_npo_med(prev.id, npo),
|
|
280
281
|
UpdateExpression: "SET #url = :url, gsi1SK = :gsi1SK",
|
|
281
282
|
ExpressionAttributeNames: { "#url": "url" },
|
|
@@ -290,7 +291,7 @@ export class NpoDb extends Db {
|
|
|
290
291
|
|
|
291
292
|
async npo_med_delete(npo: number, mid: string) {
|
|
292
293
|
const cmd = new DeleteCommand({
|
|
293
|
-
TableName: NpoDb.
|
|
294
|
+
TableName: NpoDb.table,
|
|
294
295
|
Key: this.key_npo_med(mid, npo),
|
|
295
296
|
});
|
|
296
297
|
return this.client.send(cmd);
|
|
@@ -304,7 +305,7 @@ export class NpoDb extends Db {
|
|
|
304
305
|
|
|
305
306
|
if (typeof id === "string") {
|
|
306
307
|
const cmd = new QueryCommand({
|
|
307
|
-
TableName: NpoDb.
|
|
308
|
+
TableName: NpoDb.table,
|
|
308
309
|
IndexName: NpoDb.slug_env_gsi,
|
|
309
310
|
KeyConditionExpression: "#slug = :slug and #env = :env",
|
|
310
311
|
ExpressionAttributeValues: {
|
|
@@ -323,7 +324,7 @@ export class NpoDb extends Db {
|
|
|
323
324
|
}
|
|
324
325
|
|
|
325
326
|
const cmd = new GetCommand({
|
|
326
|
-
TableName: NpoDb.
|
|
327
|
+
TableName: NpoDb.table,
|
|
327
328
|
Key: this.key_npo(id),
|
|
328
329
|
ProjectionExpression: expression,
|
|
329
330
|
ExpressionAttributeNames: names,
|
|
@@ -365,7 +366,7 @@ export class NpoDb extends Db {
|
|
|
365
366
|
async npo_update(id: number, update: INpoUpdate) {
|
|
366
367
|
const upd8 = this.npo_update_comps(update);
|
|
367
368
|
const cmd = new UpdateCommand({
|
|
368
|
-
TableName: NpoDb.
|
|
369
|
+
TableName: NpoDb.table,
|
|
369
370
|
Key: this.key_npo(id),
|
|
370
371
|
...upd8,
|
|
371
372
|
ReturnValues: "ALL_NEW",
|
|
@@ -375,7 +376,7 @@ export class NpoDb extends Db {
|
|
|
375
376
|
|
|
376
377
|
async prog_milestones(id: string): Promise<IMilestone[]> {
|
|
377
378
|
const command = new QueryCommand({
|
|
378
|
-
TableName: NpoDb.
|
|
379
|
+
TableName: NpoDb.table,
|
|
379
380
|
KeyConditionExpression: `PK = :PK`,
|
|
380
381
|
ExpressionAttributeValues: {
|
|
381
382
|
":PK": this.key_prog_milestone("not-used", id).PK,
|
|
@@ -387,7 +388,7 @@ export class NpoDb extends Db {
|
|
|
387
388
|
}
|
|
388
389
|
async prog_milestone_delete(pid: string, mid: string) {
|
|
389
390
|
const cmd = new DeleteCommand({
|
|
390
|
-
TableName: NpoDb.
|
|
391
|
+
TableName: NpoDb.table,
|
|
391
392
|
Key: this.key_prog_milestone(mid, pid),
|
|
392
393
|
});
|
|
393
394
|
return this.client.send(cmd);
|
|
@@ -398,7 +399,7 @@ export class NpoDb extends Db {
|
|
|
398
399
|
): Promise<string> {
|
|
399
400
|
const item = this.prog_milestone_record(pid, content);
|
|
400
401
|
const cmd = new PutCommand({
|
|
401
|
-
TableName: NpoDb.
|
|
402
|
+
TableName: NpoDb.table,
|
|
402
403
|
Item: item,
|
|
403
404
|
});
|
|
404
405
|
return this.client.send(cmd).then(() => item.id);
|
|
@@ -415,7 +416,7 @@ export class NpoDb extends Db {
|
|
|
415
416
|
}
|
|
416
417
|
|
|
417
418
|
const cmd = new UpdateCommand({
|
|
418
|
-
TableName: NpoDb.
|
|
419
|
+
TableName: NpoDb.table,
|
|
419
420
|
Key: this.key_prog_milestone(mid, pid),
|
|
420
421
|
...upd8.collect(),
|
|
421
422
|
ReturnValues: "ALL_NEW",
|
|
@@ -425,7 +426,7 @@ export class NpoDb extends Db {
|
|
|
425
426
|
|
|
426
427
|
async npo_program(id: string, npo_id: number): Promise<IProgram | undefined> {
|
|
427
428
|
const cmd = new GetCommand({
|
|
428
|
-
TableName: NpoDb.
|
|
429
|
+
TableName: NpoDb.table,
|
|
429
430
|
Key: this.key_npo_program(id, npo_id),
|
|
430
431
|
});
|
|
431
432
|
const { Item: p } = await this.client.send(cmd);
|
|
@@ -440,7 +441,7 @@ export class NpoDb extends Db {
|
|
|
440
441
|
}
|
|
441
442
|
async npo_programs(id: number): Promise<IProgramDb[]> {
|
|
442
443
|
const cmd = new QueryCommand({
|
|
443
|
-
TableName: NpoDb.
|
|
444
|
+
TableName: NpoDb.table,
|
|
444
445
|
KeyConditionExpression: `PK = :PK and begins_with(SK, :SK)`,
|
|
445
446
|
ExpressionAttributeValues: {
|
|
446
447
|
":PK": this.key_npo_program("not-used", id).PK,
|
|
@@ -463,13 +464,13 @@ export class NpoDb extends Db {
|
|
|
463
464
|
totalDonations: 0,
|
|
464
465
|
});
|
|
465
466
|
txs.put({
|
|
466
|
-
TableName: NpoDb.
|
|
467
|
+
TableName: NpoDb.table,
|
|
467
468
|
Item: db_prog,
|
|
468
469
|
});
|
|
469
470
|
|
|
470
471
|
for (const m of milestones || []) {
|
|
471
472
|
txs.put({
|
|
472
|
-
TableName: NpoDb.
|
|
473
|
+
TableName: NpoDb.table,
|
|
473
474
|
Item: this.prog_milestone_record(pid, m),
|
|
474
475
|
});
|
|
475
476
|
}
|
|
@@ -486,13 +487,13 @@ export class NpoDb extends Db {
|
|
|
486
487
|
const milestones = await this.prog_milestones(prog);
|
|
487
488
|
const txs = new Txs();
|
|
488
489
|
txs.del({
|
|
489
|
-
TableName: NpoDb.
|
|
490
|
+
TableName: NpoDb.table,
|
|
490
491
|
Key: this.key_npo_program(prog, npo),
|
|
491
492
|
});
|
|
492
493
|
|
|
493
494
|
for (const m of milestones) {
|
|
494
495
|
txs.del({
|
|
495
|
-
TableName: NpoDb.
|
|
496
|
+
TableName: NpoDb.table,
|
|
496
497
|
Key: this.key_prog_milestone(m.id, prog),
|
|
497
498
|
});
|
|
498
499
|
}
|
|
@@ -510,7 +511,7 @@ export class NpoDb extends Db {
|
|
|
510
511
|
}
|
|
511
512
|
|
|
512
513
|
const cmd = new UpdateCommand({
|
|
513
|
-
TableName: NpoDb.
|
|
514
|
+
TableName: NpoDb.table,
|
|
514
515
|
Key: this.key_npo_program(prog, npo),
|
|
515
516
|
...upd8.collect(),
|
|
516
517
|
ReturnValues: "ALL_NEW",
|