종목별매출통계 api수정

This commit is contained in:
이담 정 2022-08-01 05:20:25 +00:00
parent c00969fbb4
commit 6b726333dd

View File

@ -1,13 +1,13 @@
import { Injectable } from '@angular/core';
import { assign, cloneDeep } from 'lodash-es';
import { FuseMockApiService, FuseMockApiUtils } from '@fuse/lib/mock-api';
import { statistics as statisticsData } from './data';
import { statisticss as statisticssData } from './data';
@Injectable({
providedIn: 'root',
})
export class ReportStatisticsMockApi {
private _statistics: any[] = statisticsData;
private _statisticss: any[] = statisticssData;
/**
* Constructor
@ -26,10 +26,10 @@ export class ReportStatisticsMockApi {
*/
registerHandlers(): void {
// -----------------------------------------------------------------------------------------------------
// @ Statistics - GET
// @ Statisticss - GET
// -----------------------------------------------------------------------------------------------------
this._fuseMockApiService
.onGet('api/apps/report/statistics/statistics', 300)
.onGet('api/apps/report/statistics/statisticss', 300)
.reply(({ request }) => {
// Get available queries
const search = request.params.get('search');
@ -38,12 +38,12 @@ export class ReportStatisticsMockApi {
const page = parseInt(request.params.get('page') ?? '1', 10);
const size = parseInt(request.params.get('size') ?? '10', 10);
// Clone the statistics
let statistics: any[] | null = cloneDeep(this._statistics);
// Clone the statisticss
let statisticss: any[] | null = cloneDeep(this._statisticss);
// Sort the statistics
// Sort the statisticss
if (sort === 'sku' || sort === 'name' || sort === 'active') {
statistics.sort((a, b) => {
statisticss.sort((a, b) => {
const fieldA = a[sort].toString().toUpperCase();
const fieldB = b[sort].toString().toUpperCase();
return order === 'asc'
@ -51,15 +51,15 @@ export class ReportStatisticsMockApi {
: fieldB.localeCompare(fieldA);
});
} else {
statistics.sort((a, b) =>
statisticss.sort((a, b) =>
order === 'asc' ? a[sort] - b[sort] : b[sort] - a[sort]
);
}
// If search exists...
if (search) {
// Filter the statistics
statistics = statistics.filter(
// Filter the statisticss
statisticss = statisticss.filter(
(contact: any) =>
contact.name &&
contact.name.toLowerCase().includes(search.toLowerCase())
@ -67,32 +67,32 @@ export class ReportStatisticsMockApi {
}
// Paginate - Start
const statisticsLength = statistics.length;
const statisticssLength = statisticss.length;
// Calculate pagination details
const begin = page * size;
const end = Math.min(size * (page + 1), statisticsLength);
const lastPage = Math.max(Math.ceil(statisticsLength / size), 1);
const end = Math.min(size * (page + 1), statisticssLength);
const lastPage = Math.max(Math.ceil(statisticssLength / size), 1);
// Prepare the pagination object
let pagination = {};
// If the requested page number is bigger than
// the last possible page number, return null for
// statistics but also send the last possible page so
// statisticss but also send the last possible page so
// the app can navigate to there
if (page > lastPage) {
statistics = null;
statisticss = null;
pagination = {
lastPage,
};
} else {
// Paginate the results by size
statistics = statistics.slice(begin, end);
statisticss = statisticss.slice(begin, end);
// Prepare the pagination mock-api
pagination = {
length: statisticsLength,
length: statisticssLength,
size: size,
page: page,
lastPage: lastPage,
@ -105,7 +105,7 @@ export class ReportStatisticsMockApi {
return [
200,
{
statistics,
statisticss,
pagination,
},
];
@ -120,11 +120,11 @@ export class ReportStatisticsMockApi {
// Get the id from the params
const id = request.params.get('id');
// Clone the statistics
const statistics = cloneDeep(this._statistics);
// Clone the statisticss
const statisticss = cloneDeep(this._statisticss);
// Find the statistics
const statistic = statistics.find((item: any) => item.id === id);
const statistics = statisticss.find((item: any) => item.id === id);
// Return the response
return [200, statistics];
@ -160,7 +160,7 @@ export class ReportStatisticsMockApi {
};
// Unshift the new statistics
this._statistics.unshift(newStatistics);
this._statisticss.unshift(newStatistics);
// Return the response
return [200, newStatistics];
@ -180,13 +180,13 @@ export class ReportStatisticsMockApi {
let updatedStatistics = null;
// Find the statistics and update it
this._statistics.forEach((item, index, statistics) => {
this._statisticss.forEach((item, index, statisticss) => {
if (item.id === id) {
// Update the statistics
statistics[index] = assign({}, statistics[index], statistics);
statisticss[index] = assign({}, statisticss[index], statistics);
// Store the updated Statistics
updatedStatistics = statistics[index];
updatedStatistics = statisticss[index];
}
});
@ -204,9 +204,9 @@ export class ReportStatisticsMockApi {
const id = request.params.get('id');
// Find the statistics and delete it
this._statistics.forEach((item, index) => {
this._statisticss.forEach((item, index) => {
if (item.id === id) {
this._statistics.splice(index, 1);
this._statisticss.splice(index, 1);
}
});