Skip to content

Commit

Permalink
Store annotation_map
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Dec 27, 2023
1 parent 4bc5dd1 commit daf746a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/lib/database/seed-from-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ export const seedDatabaseFromApi = async (

if (hasManufacturer) continue

const { logo, ...rest } = manufacturer
const { logo, annotations, ...rest } = manufacturer
db.addManufacturer({
...rest,
annotation_map: annotations.reduce(
(acc, cur) => ({ ...acc, [cur.annotation_code]: cur }),
{},
),
logo:
logo != null
? {
Expand Down
6 changes: 6 additions & 0 deletions src/lib/database/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export const seedDatabase = (db: Database) => {
integration_support_level: "stable",
is_connect_webview_supported: true,
requires_seam_support_to_add_account: false,
annotation_map: {
subscription_required: {
annotation_code: "subscription_required",
message: "Need to subscribe",
},
},
})

const device_model = db.addDeviceModel({
Expand Down
2 changes: 1 addition & 1 deletion src/lib/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const stored_manufacturer = schemas.manufacturer
.merge(
z.object({
logo: stored_image_reference.optional(),
annotations: z
annotation_map: z
.record(
schemas.manufacturer_annotation_code,
schemas.manufacturer_annotation,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/public-mappings/manufacturer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const publicMapManufacturer = ({
}: PublicMapManufacturerOptions): Manufacturer => ({
manufacturer_id: manufacturer.manufacturer_id,
display_name: manufacturer.display_name,
annotations: Object.values(manufacturer.annotations ?? []),
annotations: Object.values(manufacturer.annotation_map ?? {}),
logo: manufacturer.logo
? publicMapImageReference({
image: manufacturer.logo,
Expand Down
3 changes: 3 additions & 0 deletions test/api/v1/manufacturers/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ test("GET /v1/manufacturers/get", async (t: ExecutionContext) => {

t.is(data.manufacturer.manufacturer_id, manufacturer.manufacturer_id)
t.is(data.manufacturer.device_model_count, 1)
t.is(data.manufacturer.annotations.length, 1)
const annotation_message = data.manufacturer.annotations[0]?.message ?? ""
t.true(annotation_message.length > 0)
})
1 change: 1 addition & 0 deletions test/seed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ test("seed database from api", async (t) => {
integration_support_level: "stable",
is_connect_webview_supported: true,
requires_seam_support_to_add_account: false,
annotation_map: {},
})

const device_model = apiDb.addDeviceModel({
Expand Down

0 comments on commit daf746a

Please sign in to comment.