Skip to content

Commit

Permalink
feat: Add manufacturer.annotations (#15)
Browse files Browse the repository at this point in the history
* feat: Add manufacturer.annotations

* ci: Generate code

* Store annotation_map

---------

Co-authored-by: Seam Bot <devops@getseam.com>
  • Loading branch information
razor-x and seambot authored Dec 27, 2023
1 parent b84754d commit 3805e57
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 24 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
},
"devDependencies": {
"@seamapi/logger": "^1.9.2",
"@seamapi/types": "^1.68.0",
"@seamapi/types": "^1.71.0",
"@tsconfig/next": "^2.0.0",
"@types/get-pixels": "^3.3.2",
"@types/lodash": "^4.14.202",
Expand Down
214 changes: 197 additions & 17 deletions public/openapi.json

Large diffs are not rendered by default.

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
8 changes: 7 additions & 1 deletion src/lib/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ export const stored_image_reference = z.object({
export type StoredImageReference = z.infer<typeof stored_image_reference>

export const stored_manufacturer = schemas.manufacturer
.omit({ device_model_count: true, logo: true })
.omit({ device_model_count: true, logo: true, annotations: true })
.merge(
z.object({
logo: stored_image_reference.optional(),
annotation_map: z
.record(
schemas.manufacturer_annotation_code,
schemas.manufacturer_annotation,
)
.optional(),
}),
)
export type StoredManufacturer = z.infer<typeof stored_manufacturer>
Expand Down
1 change: 1 addition & 0 deletions src/lib/public-mappings/manufacturer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const publicMapManufacturer = ({
}: PublicMapManufacturerOptions): Manufacturer => ({
manufacturer_id: manufacturer.manufacturer_id,
display_name: manufacturer.display_name,
annotations: Object.values(manufacturer.annotation_map ?? {}),
logo: manufacturer.logo
? publicMapImageReference({
image: manufacturer.logo,
Expand Down
16 changes: 16 additions & 0 deletions src/route-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ export type Routes = {
| "inquire"
is_connect_webview_supported: boolean
requires_seam_support_to_add_account: boolean
annotations: {
annotation_code: "subscription_required"
message: string
}[]
}
is_device_supported: boolean
display_name: string
Expand Down Expand Up @@ -235,6 +239,10 @@ export type Routes = {
| "inquire"
is_connect_webview_supported: boolean
requires_seam_support_to_add_account: boolean
annotations: {
annotation_code: "subscription_required"
message: string
}[]
}
is_device_supported: boolean
display_name: string
Expand Down Expand Up @@ -374,6 +382,10 @@ export type Routes = {
is_connect_webview_supported: boolean
requires_seam_support_to_add_account: boolean
device_model_count: number
annotations: {
annotation_code: "subscription_required"
message: string
}[]
}
}
}
Expand Down Expand Up @@ -413,6 +425,10 @@ export type Routes = {
is_connect_webview_supported: boolean
requires_seam_support_to_add_account: boolean
device_model_count: number
annotations: {
annotation_code: "subscription_required"
message: string
}[]
}[]
}
}
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 3805e57

Please sign in to comment.