Skip to content

Commit 6ab1138

Browse files
authored
feat: refactor Baserow table IDs to use configuration class (#2127)
1 parent bfb613f commit 6ab1138

File tree

6 files changed

+74
-9
lines changed

6 files changed

+74
-9
lines changed

libs/data/src/common/baserow/abstractBaserow.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import axios from 'axios'
22
import dotenv from 'dotenv'
33
import path from 'path'
44
import { fileURLToPath } from 'url'
5+
import ConfigBaserow from '../../configBaserow'
56
import { Id, LinkObject } from './types'
67

78
dotenv.config()
@@ -10,10 +11,10 @@ export abstract class AbstractBaserow {
1011
protected readonly __dirname = path.dirname(fileURLToPath(import.meta.url))
1112
private readonly _apiToken = this._setBaserowToken()
1213
private readonly _baseUrl = 'https://api.baserow.io/api'
13-
protected readonly _themeTableId = 305258
14-
protected readonly _operatorTableId = 314410
15-
protected readonly _geographicAreasTableId = 314474
16-
protected readonly _projectTableId = 305253
14+
protected readonly _themeTableId = ConfigBaserow.THEME_ID
15+
protected readonly _operatorTableId = ConfigBaserow.OPERATOR_ID
16+
protected readonly _geographicAreasTableId = ConfigBaserow.GEOGRAPHIC_AREAS_ID
17+
protected readonly _projectTableId = ConfigBaserow.PROJECT_ID
1718

1819
private readonly _axiosHeader = {
1920
headers: {

libs/data/src/common/baserow/imageBaserow.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import fs from 'fs'
22
import axios from 'axios'
33
import path from 'path'
44
import sharp from 'sharp'
5+
import ConfigBaserow from '../../configBaserow'
56
import { AbstractBaserow } from './abstractBaserow'
67
import { LinkObject, ImageTable, Image } from './types'
78
import { Result } from 'true-myth'
@@ -11,7 +12,7 @@ interface ImageMetadata {
1112
}
1213

1314
export class ImageBaserow extends AbstractBaserow {
14-
private readonly _imageTableId = 315189
15+
private readonly _imageTableId = ConfigBaserow.IMAGE_ID
1516
private _metadata: ImageMetadata = {}
1617
private _processedImages: Set<string> = new Set()
1718

libs/data/src/common/baserow/programBaserow.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'fs'
2+
import ConfigBaserow from '../../configBaserow'
23
import { AbstractBaserow } from './abstractBaserow'
34
import { ConditionalValues, Program } from './types'
45
import {
@@ -14,9 +15,9 @@ import { Theme } from '../../theme/types/domain'
1415
import { FileManager } from '../fileManager'
1516

1617
export class ProgramBaserow extends AbstractBaserow {
17-
private readonly _geographicCoverageTableId = 314470
18-
private readonly _programTableId = 314437
19-
private readonly _conditionnalValuesTableId = 351202
18+
private readonly _geographicCoverageTableId = ConfigBaserow.GEOGRAPHIC_COVERAGE_ID
19+
private readonly _programTableId = ConfigBaserow.PROGRAM_ID
20+
private readonly _conditionnalValuesTableId = ConfigBaserow.CONDITIONAL_VALUES_ID
2021
private _operators: Operator[] = []
2122
private _geographicAreas: GeographicCoverage[] = []
2223

libs/data/src/common/baserow/testimonyBaserow.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import ConfigBaserow from '../../configBaserow'
12
import { AbstractBaserow } from './abstractBaserow'
23
import { BaserowTestimony } from './types'
34
import { Testimony } from '../../testimony/types/shared'
45
import { ImageBaserow } from './imageBaserow'
56
import path from 'path'
67

78
export class TestimonyBaserow extends AbstractBaserow {
8-
private readonly _testimoniesTableId = 399896
9+
private readonly _testimoniesTableId = ConfigBaserow.TESTIMONIES_ID
910
private readonly _logPath: string = path.join(this.__dirname, '../../../static/testimony_images_download_info.json')
1011
private _imageDownloader: ImageBaserow
1112
private readonly _imagePath = '/images/testimony/'

libs/data/src/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ConfigCommon } from '@tee/common'
2+
import dotenv from 'dotenv'
3+
4+
export default class Config extends ConfigCommon {
5+
public static loadDotEnv() {
6+
dotenv.config()
7+
}
8+
}

libs/data/src/configBaserow.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { ConfigCommon } from '@tee/common'
2+
3+
export default class ConfigBaserow extends ConfigCommon {
4+
private static _TABLE_ID_CONDITIONAL_VALUES = 351202
5+
private static _TABLE_ID_GEOGRAPHIC_AREAS = 314474
6+
private static _TABLE_ID_GEOGRAPHIC_COVERAGE = 314470
7+
private static _TABLE_ID_IMAGE = 315189
8+
private static _TABLE_ID_OPERATOR = 314410
9+
private static _TABLE_ID_PROGRAM = 314437
10+
private static _TABLE_ID_PROJECT = 305253
11+
private static _TABLE_ID_TESTIMONIES = 399896
12+
private static _TABLE_ID_THEME = 305258
13+
14+
public static get TOKEN() {
15+
return this.getEnvValue('BASEROW_TOKEN')
16+
}
17+
18+
public static get CONDITIONAL_VALUES_ID() {
19+
return parseInt(this.getEnvValue('BASEROW_TABLE_ID_CONDITIONAL_VALUES', this._TABLE_ID_CONDITIONAL_VALUES.toString()))
20+
}
21+
22+
public static get GEOGRAPHIC_AREAS_ID() {
23+
return parseInt(this.getEnvValue('BASEROW_TABLE_ID_GEOGRAPHIC_AREAS', this._TABLE_ID_GEOGRAPHIC_AREAS.toString()))
24+
}
25+
26+
public static get GEOGRAPHIC_COVERAGE_ID() {
27+
return parseInt(this.getEnvValue('BASEROW_TABLE_ID_GEOGRAPHIC_COVERAGE', this._TABLE_ID_GEOGRAPHIC_COVERAGE.toString()))
28+
}
29+
30+
public static get IMAGE_ID() {
31+
return parseInt(this.getEnvValue('BASEROW_TABLE_ID_IMAGE', this._TABLE_ID_IMAGE.toString()))
32+
}
33+
34+
public static get OPERATOR_ID() {
35+
return parseInt(this.getEnvValue('BASEROW_TABLE_ID_OPERATOR', this._TABLE_ID_OPERATOR.toString()))
36+
}
37+
38+
public static get PROGRAM_ID() {
39+
return parseInt(this.getEnvValue('BASEROW_TABLE_ID_PROGRAM', this._TABLE_ID_PROGRAM.toString()))
40+
}
41+
42+
public static get PROJECT_ID() {
43+
return parseInt(this.getEnvValue('BASEROW_TABLE_ID_PROJECT', this._TABLE_ID_PROJECT.toString()))
44+
}
45+
46+
public static get TESTIMONIES_ID() {
47+
return parseInt(this.getEnvValue('BASEROW_TABLE_ID_TESTIMONIES', this._TABLE_ID_TESTIMONIES.toString()))
48+
}
49+
50+
public static get THEME_ID() {
51+
return parseInt(this.getEnvValue('BASEROW_TABLE_ID_THEME', this._TABLE_ID_THEME.toString()))
52+
}
53+
}

0 commit comments

Comments
 (0)