diff --git a/src/bases/base.service.ts b/src/bases/base.service.ts index c0b915f..1c7923f 100644 --- a/src/bases/base.service.ts +++ b/src/bases/base.service.ts @@ -14,8 +14,8 @@ export class BaseService, UpdateDto extends Part return this.repository.findAll(); } - async findById(id: number): Promise { - return this.repository.findById(id); + async findById(id: number, idColumn: string | null = 'id'): Promise { + return this.repository.findById(id, idColumn); } async create(dto: CreateDto): Promise { diff --git a/src/cw_devices/cw_devices.module.ts b/src/cw_devices/cw_devices.module.ts index 7e23d6a..4de7039 100644 --- a/src/cw_devices/cw_devices.module.ts +++ b/src/cw_devices/cw_devices.module.ts @@ -1,4 +1,3 @@ -// src/cw_devices/cw_devices.module.ts import { Module } from '@nestjs/common'; import { CwDevicesService } from './cw_devices.service'; import { CwDevicesController } from './cw_devices.controller'; diff --git a/src/location/location.module.ts b/src/location/location.module.ts index b7ddc8d..94411c4 100644 --- a/src/location/location.module.ts +++ b/src/location/location.module.ts @@ -4,14 +4,12 @@ import { LocationService } from './location.service'; import { LocationRepository } from 'src/repositories/cw_location.repository'; import { SupabaseModule } from 'src/supabase/supabase.module'; import { BaseRepository } from 'src/repositories/base.repository'; +import { AuthModule } from 'src/auth/auth.module'; @Module({ - imports: [SupabaseModule], + imports: [SupabaseModule, AuthModule, BaseRepository], + providers: [LocationService, LocationRepository], controllers: [LocationController], - providers: [ - LocationService, - LocationRepository, - BaseRepository, - ], + exports: [LocationService], }) export class LocationModule {} diff --git a/src/location/location.service.ts b/src/location/location.service.ts index ac0ed8b..1315673 100644 --- a/src/location/location.service.ts +++ b/src/location/location.service.ts @@ -4,10 +4,12 @@ import { UpdateLocationDto } from './dto/update-location.dto'; import { BaseService } from 'src/bases/base.service'; import { BaseRepository } from 'src/repositories/base.repository'; import { LocationRow } from 'src/common/database-types'; +import { LocationRepository } from 'src/repositories/cw_location.repository'; @Injectable() export class LocationService extends BaseService { - constructor(repository: BaseRepository) { + // constructor(repository: BaseRepository) { + constructor(repository: LocationRepository) { super(repository); } diff --git a/src/main.ts b/src/main.ts index 6dc1981..81b26b6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,6 +22,14 @@ async function bootstrap() { background: #125d2b !important; } + .swagger-container { + background: #ebebeb !important; + } + + #logo_small_svg__SW_TM-logo-on-dark { + display: none; + } + /* 2. Center the logo + text horizontally in the top bar */ #swagger-ui .topbar .wrapper .topbar-wrapper { display: flex; diff --git a/src/pdf/PdfTemplateTypes/Co2Report.ts b/src/pdf/PdfTemplateTypes/Co2Report.ts index da2de4a..287eb41 100644 --- a/src/pdf/PdfTemplateTypes/Co2Report.ts +++ b/src/pdf/PdfTemplateTypes/Co2Report.ts @@ -9,7 +9,15 @@ import moment from 'moment'; // PARTS: -export async function buildCO2Report(reportData): Promise { +export async function buildCO2Report( + reportData, + devEui: string = 'n/a', + companyName: string = 'n/a', + department: string = 'n/a', + usageLocation: string = 'n/a', + sensorName: string = 'n/a', + startToEndString: string = 'n/a' +): Promise { return new Promise(async (resolve, reject) => { try { // Create a new PDF document @@ -22,7 +30,7 @@ export async function buildCO2Report(reportData): Promise { doc.font('NotoSansJP'); doc.x = doc.page.margins.left; - doc.fontSize(14).text('Chicken Environment Report', 0, 0, { width: doc.page.width, align: 'center' }); + doc.fontSize(14).text('CO2 Report', 0, 0, { width: doc.page.width, align: 'center' }); doc.x = doc.page.margins.left; // Collect chunks in memory @@ -47,12 +55,12 @@ export async function buildCO2Report(reportData): Promise { const dataGroups = { group1: [ - { label: '会社:', value: 'Acme Corp' }, - { label: '部署:', value: 'Engineering' }, - { label: '使用場所:', value: 'Warehouse 7' }, - { label: 'センサー名:', value: 'Thermometer A1' }, - { label: '測定期間:', value: '2024/04/19 - 2024/04/25' }, - { label: 'DevEUI:', value: '373632336F32840A' } + { label: '会社:', value: companyName }, + { label: '部署:', value: department }, + { label: '使用場所:', value: usageLocation }, + { label: 'センサー名:', value: sensorName }, + { label: '測定期間:', value: startToEndString }, + { label: 'DevEUI:', value: devEui } ], group2: [ { label: 'データタイプ:', value: 'Temperature' }, @@ -80,10 +88,10 @@ export async function buildCO2Report(reportData): Promise { doc.x = 0; drawFourDataGroups(doc, dataGroups, { fontSize: 6, - rowHeight: 18, + rowHeight: 20, labelWidth: 65, valueWidth: 78, - gapBetweenCols: 0, + gapBetweenCols: 3, drawColumnDividers: true, labelGap: 10, alternateRowShading: true, @@ -103,8 +111,8 @@ export async function buildCO2Report(reportData): Promise { { key: 'createdAt', label: '日時', width: 75 }, { key: 'temperature', label: '温度', width: 30 }, { key: 'humidity', label: '湿度', width: 30 }, - { key: 'co2', label: 'CO2', width: 35 }, - { key: 'comment', label: 'コメント', width: 80 }, + { key: 'co2', label: 'CO2', width: 37 }, + { key: 'comment', label: 'コメント', width: 85 }, ]; // data: e.g. from diff --git a/src/pdf/data-formatters/legacy-test.ts b/src/pdf/data-formatters/legacy-test.ts index af58f48..80bd968 100644 --- a/src/pdf/data-formatters/legacy-test.ts +++ b/src/pdf/data-formatters/legacy-test.ts @@ -25,7 +25,7 @@ interface RawRecord { department: string | undefined, usageLocation: string, sensorName: string, - devEui: string + devEui: string, ): pdfReportFormat { // Extract the array const records = raw.reportData; diff --git a/src/pdf/pdf.module.ts b/src/pdf/pdf.module.ts index 68f2cb3..b1dc19b 100644 --- a/src/pdf/pdf.module.ts +++ b/src/pdf/pdf.module.ts @@ -8,10 +8,15 @@ import { CwDeviceTypeModule } from 'src/cw_device_type/cw_device_type.module'; import { CwDeviceOwnersModule } from 'src/cw_device_owners/cw_device_owners.module'; import { AuthService } from 'src/auth/auth.service'; import { ReportsTemplatesModule } from 'src/reports_templates/reports_templates.module'; +import { LocationService } from 'src/location/location.service'; +import { LocationModule } from 'src/location/location.module'; +import { ProfilesModule } from 'src/profiles/profiles.module'; @Module({ imports: [ DataModule, + LocationModule, + ProfilesModule, CwDevicesModule, CwDeviceTypeModule, CwDeviceOwnersModule, diff --git a/src/pdf/pdf.service.ts b/src/pdf/pdf.service.ts index 6a35d3e..76a473a 100644 --- a/src/pdf/pdf.service.ts +++ b/src/pdf/pdf.service.ts @@ -8,14 +8,18 @@ import { CwDevicesService } from 'src/cw_devices/cw_devices.service'; import { pdfReportFormat } from './interfaces/report.interface'; import { buildColdChainReport } from './PdfTemplateTypes/ColdChain'; import { buildCO2Report } from './PdfTemplateTypes/Co2Report'; +import { LocationService } from 'src/location/location.service'; +import { ProfilesService } from 'src/profiles/profiles.service'; +import moment from 'moment'; @Injectable() export class PdfService { constructor( private readonly dataService: DataService, - private readonly reportsTemplatesService: ReportsTemplatesService, private readonly deviceService: CwDevicesService, + private readonly locationService: LocationService, + private readonly profileService: ProfilesService ) { } public async createPdfBinary(user_id: string, devEui: string, start: Date, end: Date): Promise { @@ -23,19 +27,21 @@ export class PdfService { if (!devEui) throw new Error('DevEui is required'); let rawData = await this.fetchDataAndReportFromDB(devEui, user_id, start, end); let device = await this.deviceService.getDeviceByDevEui(devEui); + let location = await this.locationService.findById(device.location_id, 'location_id'); + let profile = await this.profileService.findOne(device.user_id); const pdfReport = await mapToPdfReport( rawData, - 'Acme Corp', // company - 'Engineering', // department - 'Warehouse 7', // usage location + device.dev_eui, // devEui + profile.employer, // company + '--', // department + location.name, // usage location device.name, // sensor name - devEui // devEui ); if (device.report_endpoint.includes('cold-storage')) { return await buildColdChainReport(pdfReport); } else if (device.report_endpoint.includes('co2-report')) { - return await buildCO2Report(rawData); + return await buildCO2Report(rawData, device.dev_eui, profile.employer, '--', location.name, `${moment(start).format('YYYY/MM/DD').toString()} - ${moment(end).format('YYYY/MM/DD').toString()}`); } else { throw new Error('Report endpoint not found'); } diff --git a/src/profiles/profiles.module.ts b/src/profiles/profiles.module.ts index c894311..50c000a 100644 --- a/src/profiles/profiles.module.ts +++ b/src/profiles/profiles.module.ts @@ -1,7 +1,6 @@ import { Module } from '@nestjs/common'; import { ProfilesService } from './profiles.service'; import { ProfilesController } from './profiles.controller'; -import { SupabaseService } from 'src/supabase/supabase.service'; import { ProfileRepository } from 'src/repositories/profiles.repositories'; import { SupabaseModule } from 'src/supabase/supabase.module'; @@ -9,5 +8,6 @@ import { SupabaseModule } from 'src/supabase/supabase.module'; imports: [SupabaseModule], controllers: [ProfilesController], providers: [ProfilesService, ProfileRepository], + exports: [ProfilesService] }) export class ProfilesModule { } diff --git a/src/repositories/profiles.repositories.ts b/src/repositories/profiles.repositories.ts index fafdff1..75fec7c 100644 --- a/src/repositories/profiles.repositories.ts +++ b/src/repositories/profiles.repositories.ts @@ -9,15 +9,15 @@ export class ProfileRepository { @ApiBearerAuth('JWT') async findById(id: string): Promise { - const {data: user, error: userError } = await this.supabaseService.getSupabaseClient().auth.getUser(id); - if (userError) { - throw userError; - } + // const {data: user, error: userError } = await this.supabaseService.getSupabaseClient().auth.getUser(id); + // if (userError) { + // throw userError; + // } const { data, error } = await this.supabaseService .getSupabaseClient() .from('profiles') .select('*') - .eq('id', user.user.id) + .eq('id', id) .single(); if (error) { throw error;