-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into docs/README
- Loading branch information
Showing
17 changed files
with
158 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
...rver/src/clouds/clouds.controller.spec.ts → ...server/src/cloud/cloud.controller.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Controller, Get } from '@nestjs/common'; | ||
import { CloudService } from './cloud.service'; | ||
|
||
@Controller('cloud') | ||
export class CloudController { | ||
constructor(private readonly service: CloudService) {} | ||
|
||
@Get('/prices') | ||
getCloudResorucePrices() { | ||
return this.service.findCloudResourcePrices(); | ||
} | ||
|
||
// @Get('/test') | ||
// getTestPrices() { | ||
// return this.service.calculatePrice(); | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { CloudController } from './cloud.controller'; | ||
import { CloudService } from './cloud.service'; | ||
import { PrismaModule } from 'src/prisma/prisma.module'; | ||
|
||
@Module({ | ||
imports: [PrismaModule], | ||
controllers: [CloudController], | ||
providers: [CloudService], | ||
exports: [CloudService], | ||
}) | ||
export class CloudModule {} |
10 changes: 5 additions & 5 deletions
10
.../server/src/clouds/clouds.service.spec.ts → apps/server/src/cloud/cloud.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { InjectRedis } from '@nestjs-modules/ioredis'; | ||
import { Injectable, NotFoundException } from '@nestjs/common'; | ||
import Redis from 'ioredis'; | ||
import { PrismaService } from 'src/prisma/prisma.service'; | ||
|
||
@Injectable() | ||
export class CloudService { | ||
constructor( | ||
private readonly prisma: PrismaService, | ||
@InjectRedis() private readonly redis: Redis, | ||
) {} | ||
|
||
async findCloudResourcePrices() { | ||
return Object.fromEntries(await this.getCloudResourcesMap()); | ||
} | ||
|
||
async calculatePrice(nodes: Record<string, any>) { | ||
if (nodes && !Object.keys(nodes).length) throw new NotFoundException(); | ||
const cloudResourcesPriceMap = await this.getCloudResourcesMap(); | ||
const nodeValues = Object.values(nodes); | ||
const totalMonthPrice = nodeValues.reduce( | ||
(price, nodeValue): number => { | ||
if (nodeValue.properties['server_spec_code']) { | ||
if ( | ||
!cloudResourcesPriceMap.has( | ||
nodeValue.properties['server_spec_code'], | ||
) | ||
) | ||
throw new NotFoundException(); | ||
price += cloudResourcesPriceMap.get( | ||
nodeValue.properties['server_spec_code'], | ||
).monthCost as number; | ||
return price; | ||
} | ||
return price; | ||
}, | ||
0, | ||
); | ||
return { totalMonthPrice }; | ||
} | ||
|
||
private async getCloudResourcesMap() { | ||
const cachePrices = JSON.parse(await this.redis.get('cloudResource')); | ||
const prices = | ||
cachePrices || | ||
(await this.prisma.ncloudServerResource.findMany({ | ||
select: { | ||
serverSpecCode: true, | ||
productName: true, | ||
hourCost: true, | ||
monthCost: true, | ||
}, | ||
})); | ||
const priceMap = new Map<string, Record<string, number | string>>(); | ||
prices.map((price) => { | ||
const { productName, hourCost, monthCost } = price; | ||
priceMap.set(price.serverSpecCode, { | ||
productName, | ||
hourCost, | ||
monthCost, | ||
}); | ||
}); | ||
return priceMap; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...esources/ncloud-resources.service.spec.ts → ...-resource/ncloud-resource.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.