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