Skip to content

Commit f1f8a69

Browse files
committed
Add region to series
1 parent 824f852 commit f1f8a69

File tree

7 files changed

+49
-11
lines changed

7 files changed

+49
-11
lines changed

app/dtos/series.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ export class MinimalSeriesDto extends BaseModelDto {
1515
@nameApiProperty()
1616
declare name: string
1717

18+
@ApiProperty({
19+
description: 'The region of the book, e.g., "us", "ca", "uk".',
20+
type: 'string',
21+
enum: ['us', 'ca', 'uk', 'au', 'fr', 'de', 'jp', 'it', 'in', 'es', 'br'],
22+
example: 'us',
23+
nullable: true,
24+
})
25+
declare region: 'us' | 'ca' | 'uk' | 'au' | 'fr' | 'de' | 'jp' | 'it' | 'in' | 'es' | 'br' | null
26+
1827
@ApiProperty({
1928
description: 'The position of the series in the list. Can be a string!',
2029
type: 'string',
@@ -32,6 +41,7 @@ export class MinimalSeriesDto extends BaseModelDto {
3241
if (!series) return
3342
this.asin = series.asin
3443
this.name = series.title ?? null
44+
this.region = series.region ?? null
3545
if (series.$extras.pivot_position) {
3646
this.position = series.$extras.pivot_position
3747
} else {

app/helper/book.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export class BookHelper {
5252
(book.releaseDate <= DateTime.now() && book.releaseDate >= book.updatedAt) ||
5353
(!book.contentType && !book.contentDeliveryType) ||
5454
!book.sku ||
55-
!book.skuGroup
55+
!book.skuGroup ||
56+
(book.series && book.series.some((s) => s.region === null || s.region === undefined))
5657
)
5758
.map((book) => book.asin)
5859

@@ -220,6 +221,7 @@ export class BookHelper {
220221
const seriesModel = new Series()
221222
seriesModel.asin = seriesData.asin ? seriesData.asin.replace('\t', '').trim() : null
222223
seriesModel.title = seriesData.title ? seriesData.title.replace('\t', '').trim() : null
224+
seriesModel.region = region
223225
seriesModel.description = seriesData.description ?? null
224226

225227
if (seriesData.sequence && seriesData.sequence.length > 0) {
@@ -240,6 +242,7 @@ export class BookHelper {
240242
if (seriesData.asin && seriesData.title) {
241243
const seriesModel = new Series()
242244
seriesModel.asin = seriesData.asin ? seriesData.asin.replace('\t', '').trim() : null
245+
seriesModel.region = region
243246
seriesModel.title = seriesData.title
244247
? seriesData.title.replace('\t', '').trim()
245248
: null

app/helper/series.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class SeriesHelper {
7777
series.fetchedDescription = true
7878
series.asin = json.product!.asin
7979
series.title = json.product!.title
80-
80+
series.region = payload.region
8181
return retryOnUniqueViolation(async () => {
8282
return await series!.save()
8383
})

app/models/series.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export default class Series extends BaseModel {
1313
@column()
1414
declare description: string
1515

16+
@column()
17+
// @enum(us, ca, uk, au, fr, de, jp, it, in, es, br)
18+
declare region: 'us' | 'ca' | 'uk' | 'au' | 'fr' | 'de' | 'jp' | 'it' | 'in' | 'es' | 'br'
19+
1620
@manyToMany(() => Book)
1721
declare books: ManyToMany<typeof Book>
1822

config/logger.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ const loggerConfig = defineConfig({
1717
transport: {
1818
targets: [
1919
...targets().pushIf(!app.inProduction, targets.pretty()).toArray(),
20-
{
21-
target: '@axiomhq/pino',
22-
options: {
23-
dataset: process.env.AXIOM_DATASET,
24-
token: process.env.AXIOM_TOKEN,
25-
},
26-
},
20+
...targets()
21+
.pushIf(!!process.env.AXIOM_DATASET && !!process.env.AXIOM_TOKEN, {
22+
target: '@axiomhq/pino',
23+
options: {
24+
dataset: process.env.AXIOM_DATASET,
25+
token: process.env.AXIOM_TOKEN,
26+
},
27+
})
28+
.toArray(),
2729
],
2830
},
2931
},
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { BaseSchema } from '@adonisjs/lucid/schema'
2+
3+
export default class extends BaseSchema {
4+
protected tableName = 'series'
5+
6+
async up() {
7+
this.schema.alterTable(this.tableName, (table) => {
8+
table
9+
.enum('region', ['us', 'ca', 'uk', 'au', 'fr', 'de', 'jp', 'it', 'in', 'es', 'br'])
10+
.nullable()
11+
})
12+
}
13+
14+
async down() {
15+
this.schema.alterTable(this.tableName, (table) => {
16+
table.dropColumn('region')
17+
})
18+
}
19+
}

start/env.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ export default await Env.create(new URL('../', import.meta.url), {
3535
REDIS_PORT: Env.schema.number(),
3636
REDIS_PASSWORD: Env.schema.string.optional(),
3737

38-
AXIOM_DATASET: Env.schema.string(),
38+
AXIOM_DATASET: Env.schema.string.optional(),
3939

40-
AXIOM_TOKEN: Env.schema.string(),
40+
AXIOM_TOKEN: Env.schema.string.optional(),
4141

4242
/*
4343
|----------------------------------------------------------

0 commit comments

Comments
 (0)