Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CON-453 add delete stock functions #41

Merged
merged 5 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/fft-api/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const MAX_ARRAY_SIZE = 500;
arnoerpenbeck marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions src/fft-api/common/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './fftApiClientService';
export * from './constants';
54 changes: 47 additions & 7 deletions src/fft-api/stock/fftStockService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Logger } from 'tslog';
import { FftApiClient } from '../common';
import { FftApiClient, MAX_ARRAY_SIZE } from '../common';
import {
FacilityServiceType,
FacilityStatus,
Expand Down Expand Up @@ -52,12 +52,12 @@ export class FftStockService {
}

if (tenantArticleIds) {
tenantArticleIds = tenantArticleIds.slice(0, 499);
tenantArticleIds = tenantArticleIds.slice(0, MAX_ARRAY_SIZE);
queryParams['tenantArticleId'] = tenantArticleIds;
}

if (locationRefs) {
locationRefs = locationRefs.slice(0, 499);
locationRefs = locationRefs.slice(0, MAX_ARRAY_SIZE);
queryParams['locationRef'] = locationRefs;
}

Expand Down Expand Up @@ -136,6 +136,9 @@ export class FftStockService {
},
};
}
if (stockIds) {
stockIds = stockIds.slice(0, MAX_ARRAY_SIZE);
}
const action = {
action: {
name: StockActionResult.NameEnum.DELETEBYIDS,
Expand Down Expand Up @@ -165,6 +168,9 @@ export class FftStockService {
},
};
}
if (tenantArticleIds) {
tenantArticleIds = tenantArticleIds.slice(0, MAX_ARRAY_SIZE);
}
const action = {
action: {
name: StockActionResult.NameEnum.DELETEBYPRODUCTS,
Expand Down Expand Up @@ -195,6 +201,9 @@ export class FftStockService {
},
};
}
if (locationIds) {
locationIds = locationIds.slice(0, MAX_ARRAY_SIZE);
}
const action = {
action: {
name: StockActionResult.NameEnum.DELETEBYLOCATIONS,
Expand All @@ -215,6 +224,37 @@ export class FftStockService {
}
}

public async moveToLocation(
fromStockId: string,
toLocationId: string,
amount: number,
deleteFromStockIfZero = true
): Promise<StockActionResult> {
const action = {
action: {
name: StockActionResult.NameEnum.MOVETOLOCATION,
fromStockId,
toLocationRef: toLocationId,
amount,
options: {
deleteFromStockIfZero,
},
},
};
try {
return await this.apiClient.post<StockActionResult>(`${this.path}/actions`, action);
} catch (error) {
const httpError = error as ResponseError;
this.logger.error(
`Could not move stock ${fromStockId} to location ${toLocationId}. Failed with status ${
httpError.status
}, error: ${httpError.response ? JSON.stringify(httpError.response.body) : ''}`
);

throw error;
}
}

public async getById(stockId: string): Promise<Stock> {
try {
return await this.apiClient.get<Stock>(`${this.path}/${stockId}`);
Expand Down Expand Up @@ -260,7 +300,7 @@ export class FftStockService {
}

if (facilityRefs) {
facilityRefs = facilityRefs.slice(0, 499);
facilityRefs = facilityRefs.slice(0, MAX_ARRAY_SIZE);
queryParams['facilityRefs'] = facilityRefs;
}

Expand All @@ -269,12 +309,12 @@ export class FftStockService {
}

if (tenantArticleIds) {
tenantArticleIds = tenantArticleIds.slice(0, 499);
tenantArticleIds = tenantArticleIds.slice(0, MAX_ARRAY_SIZE);
queryParams['tenantArticleIds'] = tenantArticleIds;
}

if (channelRefs) {
channelRefs = channelRefs.slice(0, 49);
channelRefs = channelRefs.slice(0, 50);
queryParams['channelRefs'] = channelRefs;
}
return await this.apiClient.get<StockSummaries>(`${this.path}/summaries`, queryParams);
Expand Down Expand Up @@ -318,7 +358,7 @@ export class FftStockService {
}

if (facilityIds) {
facilityIds = facilityIds.slice(0, 499);
facilityIds = facilityIds.slice(0, MAX_ARRAY_SIZE);
queryParams['facilityIds'] = facilityIds;
}

Expand Down