Skip to content

Commit

Permalink
fix: import bal data from api depot
Browse files Browse the repository at this point in the history
  • Loading branch information
MaGOs92 committed Dec 12, 2023
1 parent 29e4824 commit f6750ef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export class PopulateService {

private async extractFromApiDepot(codeCommune: string) {
try {
const response =
const fileData =
await this.apiDepotService.downloadCurrentRevisionFile(codeCommune);

const result = await extractFromCsv(response.data, codeCommune);
const result = await extractFromCsv(fileData, codeCommune);

if (!result.isValid) {
throw new Error('Invalid CSV file');
Expand Down
1 change: 1 addition & 0 deletions libs/shared/src/modules/api_depot/api_depot.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ApiDepotService } from './api_depot.service';

@Module({
imports: [
ConfigModule,
HttpModule.registerAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
Expand Down
13 changes: 10 additions & 3 deletions libs/shared/src/modules/api_depot/api_depot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ import * as hasha from 'hasha';
import { Habilitation } from './types/habilitation.type';
import { BaseLocale } from '@/shared/schemas/base_locale/base_locale.schema';
import { Revision } from '@/shared/modules/api_depot/types/revision.type';
import { ConfigService } from '@nestjs/config';

@Injectable()
export class ApiDepotService {
constructor(private readonly httpService: HttpService) {}
constructor(
private readonly httpService: HttpService,
private readonly configService: ConfigService,
) {}

async findOneHabiliation(habilitationId: string): Promise<Habilitation> {
const { data } = await firstValueFrom(
Expand Down Expand Up @@ -200,8 +204,11 @@ export class ApiDepotService {
return revisions;
}

public async downloadCurrentRevisionFile(codeCommune: string) {
const currentRevisionUrl = `/communes/${codeCommune}/current-revision/files/bal/download`;
public async downloadCurrentRevisionFile(
codeCommune: string,
): Promise<Buffer> {
const apiDepotUrl = this.configService.get<string>('API_DEPOT_URL');
const currentRevisionUrl = `${apiDepotUrl}/communes/${codeCommune}/current-revision/files/bal/download`;

const response = await this.httpService.axiosRef({
url: currentRevisionUrl,
Expand Down

0 comments on commit f6750ef

Please sign in to comment.