POST /sync starts the full synchronization in the background (202, or 409 when one is already running). Entities are synced in dependency order: brands, categories, suppliers, products (with versions and stocks), customers. Each row is synced independently so that a failure is logged without stopping the rest. Replaces the default AppService.
18 lines
668 B
TypeScript
18 lines
668 B
TypeScript
import { ConflictException, Controller, HttpCode, HttpStatus, Post } from '@nestjs/common';
|
|
import { HiboutikService } from './services/hiboutik/hiboutik.service';
|
|
|
|
@Controller()
|
|
export class AppController {
|
|
constructor(private readonly hiboutikService: HiboutikService) {}
|
|
|
|
/** Starts the synchronization in the background and answers immediately: 202, or 409 if one is already running. */
|
|
@Post('sync')
|
|
@HttpCode(HttpStatus.ACCEPTED)
|
|
hiboutikSync() {
|
|
if (!this.hiboutikService.startSync()) {
|
|
throw new ConflictException('A Hiboutik synchronization is already in progress');
|
|
}
|
|
return { message: 'Hiboutik synchronization started' };
|
|
}
|
|
}
|