Skip to content

Commit f26c754

Browse files
committed
diff assets
1 parent f05c672 commit f26c754

3 files changed

Lines changed: 42 additions & 18 deletions

File tree

api-server/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
This file documents changes to the Deconf API Server.
44

5-
## 0.1.0
5+
## 0.1.2
6+
7+
- **new** Stage and diff assets during upsert-schedule
8+
9+
## 0.1.1
610

711
🎉 Everything is new!

api-server/source/admin/admin-lib.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { HTTPError, SqlDependency, Structure } from "gruber";
22
import {
33
assertRequestParam,
4+
AssetTable,
45
ConferenceTable,
56
ContentTable,
67
LabelTable,
@@ -125,11 +126,17 @@ export async function _assertConferenceData(
125126
sql`session_id IN ${sql(getRecordIds(sessions))}`,
126127
);
127128

129+
const assets = await AssetTable.select(
130+
sql,
131+
sql`conference_id = ${conference.id}`,
132+
);
133+
128134
return {
129135
conference,
130136
sessions,
131137
people,
132138
content,
139+
assets,
133140

134141
taxonomies,
135142
labels,
@@ -153,7 +160,7 @@ interface Unwraped<T> {
153160
records: T[];
154161
}
155162

156-
export interface UnwrapOptions {
163+
export interface PerformDiffOptions {
157164
insert?: boolean;
158165
update?: boolean;
159166
delete?: boolean;
@@ -174,7 +181,7 @@ export async function _performDiff<
174181
diff: Differential<T>,
175182
table: TableDefinition<U>,
176183
map: (value: T) => Partial<U>,
177-
options: UnwrapOptions = {},
184+
options: PerformDiffOptions = {},
178185
): Promise<Unwraped<U>> {
179186
const lookup = new Map<string, number>();
180187
let records: U[] = [];

api-server/source/admin/upsert-schedule.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { assertRequestBody, defineRoute, Structure } from "gruber";
22

33
import {
4+
AssetRecord,
5+
AssetTable,
46
LabelRecord,
57
LabelTable,
68
PersonRecord,
@@ -21,12 +23,12 @@ import {
2123
useStore,
2224
} from "../lib/mod.ts";
2325
import {
26+
_assertConferenceData,
2427
_diffRelationship,
2528
_diffResource,
2629
_getRelated,
2730
_performDiff,
2831
_totalDiffs,
29-
_assertConferenceData,
3032
} from "./admin-lib.ts";
3133

3234
// The shape of the accepted HTTP request body
@@ -47,13 +49,8 @@ const _Request = Structure.object({
4749
people: Structure.array(
4850
Structure.object({
4951
id: Structure.string(),
50-
...PersonTable.fields([
51-
"avatar_id",
52-
"bio",
53-
"name",
54-
"subtitle",
55-
"metadata",
56-
]),
52+
avatar_id: Structure.union([Structure.null(), Structure.string()]),
53+
...PersonTable.fields(["bio", "name", "subtitle", "metadata"]),
5754
}),
5855
),
5956
sessions: Structure.array(
@@ -94,6 +91,12 @@ const _Request = Structure.object({
9491
...SessionLinkTable.fields(["title", "url", "metadata"]),
9592
}),
9693
),
94+
assets: Structure.array(
95+
Structure.object({
96+
id: Structure.string(),
97+
...AssetTable.fields(["title", "url", "metadata"]),
98+
}),
99+
),
97100
});
98101

99102
export const upsertScheduleRoute = defineRoute({
@@ -133,6 +136,8 @@ export const upsertScheduleRoute = defineRoute({
133136
["label_id", "session_id"],
134137
[data.labels, data.sessions],
135138
),
139+
140+
assets: _diffResource(body.assets, "id", data.assets),
136141
};
137142

138143
// Exit early & output information if the dry run flag was passed in the URL
@@ -188,19 +193,27 @@ export const upsertScheduleRoute = defineRoute({
188193
}),
189194
);
190195

196+
const assets = await _performDiff(
197+
trx,
198+
diff.assets,
199+
AssetTable,
200+
(value): Partial<AssetRecord> => ({
201+
...pickProperties(value, ["title", "url", "metadata"]),
202+
conference_id: data.conference.id,
203+
}),
204+
{ delete: false },
205+
);
206+
191207
const people = await _performDiff(
192208
trx,
193209
diff.people,
194210
PersonTable,
195211
(value): Partial<PersonRecord> => ({
196-
...pickProperties(value, [
197-
"avatar_id",
198-
"bio",
199-
"name",
200-
"subtitle",
201-
"metadata",
202-
]),
212+
...pickProperties(value, ["bio", "name", "subtitle", "metadata"]),
203213
conference_id: data.conference.id,
214+
avatar_id: value.avatar_id
215+
? _getRelated(assets.lookup, value.avatar_id)
216+
: null,
204217
}),
205218
);
206219

0 commit comments

Comments
 (0)