Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Commit

Permalink
feat: finish Bandwagon Module
Browse files Browse the repository at this point in the history
  • Loading branch information
YanceyOfficial committed Dec 11, 2019
1 parent fa4bef9 commit dc249d5
Show file tree
Hide file tree
Showing 17 changed files with 235 additions and 177 deletions.
77 changes: 0 additions & 77 deletions docs/graphql.md

This file was deleted.

75 changes: 75 additions & 0 deletions gql/open-source.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
mutation CreateOpenSource {
createOpenSource(
input: {
title: "test4"
description: "1test2"
url: "https://t4est3.com"
posterUrl: "https://1test4.com"
}
) {
_id
title
description
url
posterUrl
createdAt
updatedAt
}
}

query GetOpenSources{
getOpenSources {
_id
title
description
url
posterUrl
createdAt
updatedAt
}
}

mutation UpdateOpenSourceById {
updateOpenSourceById(
input: {
id: "f4b445d6-d569-4a29-a760-da497675db38"
title: "test2"
description: "test2"
url: "https://test2.com"
posterUrl: "https://test2.com"
}
) {
_id
title
description
url
posterUrl
createdAt
updatedAt
}
}

mutation DeleteOpenSourceById {
deleteOpenSourceById(id: "f4b445d6-d569-4a29-a760-da497675db38") {
_id
title
description
url
posterUrl
createdAt
updatedAt
}
}

mutation DeleteOpenSources {
deleteOpenSources(
ids: [
"60e5c5a2-f69f-41df-bc04-53f9c699e498"
"00c602bd-e364-491d-abb1-45cf930ac443"
]
) {
n
ok
deletedCount
}
}
20 changes: 20 additions & 0 deletions gql/sms.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
mutation SendSMS {
sendSMS(
input: {
phoneNumber: "150111896x39"
}
) {
verificationCode
}
}

mutation ValidateSMS {
validateSMS(
input: {
phoneNumber: "15011189639x",
verificationCode:"3213"
}
) {
success
}
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@
"@nestjs/typeorm": "^6.2.0",
"ali-oss": "^6.3.1",
"apollo-server-express": "^2.9.13",
"axios": "^0.19.0",
"bcrypt": "^3.0.7",
"body-parser": "^1.19.0",
"class-transformer": "^0.2.3",
"class-validator": "^0.11.0",
"compression": "^1.7.4",
"csurf": "^1.10.0",
"dotenv": "^8.2.0",
"express-rate-limit": "^5.0.0",
Expand Down Expand Up @@ -75,7 +75,6 @@
"@nestjs/testing": "^6.10.8",
"@types/ali-oss": "^6.0.4",
"@types/bcrypt": "^3.0.0",
"@types/compression": "^1.0.1",
"@types/csurf": "^1.9.36",
"@types/dotenv": "^8.2.0",
"@types/express-rate-limit": "^3.3.3",
Expand Down
58 changes: 58 additions & 0 deletions schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type Query {
getAllSMS: [SMSModel!]!
getOpenSources: [OpenSourceModel!]!
getOpenSourceById(id: ID!): OpenSourceModel!
getBanwagonServiceInfo: ServiceInfoModel!
getBanwagonUsageStats: [UsageStatesModel!]!
}

input SendSMSInput {
Expand All @@ -66,6 +68,54 @@ type SendSMSRes {
verificationCode: String!
}

type ServiceInfoModel {
vm_type: String!
ve_status: String!
ve_mac1: String!
ve_used_disk_space_b: String!
is_cpu_throttled: String!
ssh_port: Float!
live_hostname: String!
load_average: String!
mem_available_kb: Float!
swap_total_kb: Float!
swap_available_kb: Float!
hostname: String!
node_ip: String!
node_alias: String!
node_location: String!
node_location_id: String!
node_datacenter: String!
location_ipv6_ready: Boolean!
plan: String!
plan_monthly_data: Float!
monthly_data_multiplier: Float!
plan_disk: Float!
plan_ram: Float!
plan_swap: Float!
plan_max_ipv6s: Float!
os: String!
email: String!
data_counter: Float!
data_next_reset: Float!
ip_addresses: [String!]!
private_ip_addresses: [String!]!
ip_nullroutes: [String!]!
iso1: String
iso2: String
available_isos: [String!]!
plan_private_network_available: Boolean!
location_private_network_available: Boolean!
rdns_api_available: Boolean!
ptr: String!
suspended: Boolean!
policy_violation: Boolean!
suspension_count: Float
max_abuse_points: Float!
error: Float!
veid: Float!
}

type SMSModel {
_id: String!
phoneNumber: String!
Expand All @@ -82,6 +132,14 @@ input UpdateOpenSourceInput {
id: String!
}

type UsageStatesModel {
timestamp: String!
network_in_bytes: String!
network_out_bytes: String!
disk_read_bytes: String!
cpu_usage: String!
}

input ValidateSMSInput {
phoneNumber: String!
verificationCode: String!
Expand Down
10 changes: 9 additions & 1 deletion src/bandwagon/bandwagon.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { Module } from '@nestjs/common'
import { Module, HttpModule } from '@nestjs/common'
import { BandwagonService } from './bandwagon.service'
import { BandwagonResolver } from './bandwagon.resolver'

@Module({
imports: [
HttpModule.registerAsync({
useFactory: () => ({
timeout: 5000,
maxRedirects: 5,
}),
}),
],
providers: [BandwagonService, BandwagonResolver],
})
export class BandwagonModule {}
17 changes: 11 additions & 6 deletions src/bandwagon/bandwagon.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
// import { UseGuards } from '@nestjs/common'
import { Resolver, Query } from '@nestjs/graphql'
import { BandwagonService } from './bandwagon.service'
import { ServerInfoModel } from './models/server-info.model'
import { ServiceInfoModel } from './models/service-info.model'
import { UsageStatesModel } from './models/usage-stats.model'
// import { GqlAuthGuard } from '../guard/gqlAuth.guard'

@Resolver(() => ServerInfoModel)
@Resolver('Bandwagon')
export class BandwagonResolver {
constructor(private readonly bandwagonService: BandwagonService) {
this.bandwagonService = bandwagonService
}

@Query(() => ServerInfoModel)
public async getServiceInfo() {
@Query(() => ServiceInfoModel)
// @UseGuards(GqlAuthGuard)
public getBanwagonServiceInfo() {
return this.bandwagonService.getServiceInfo()
}

@Query(() => [ServerInfoModel])
public async getUsageStats() {
@Query(() => [UsageStatesModel])
// @UseGuards(GqlAuthGuard)
public getBanwagonUsageStats() {
return this.bandwagonService.getUsageStats()
}
}
33 changes: 27 additions & 6 deletions src/bandwagon/bandwagon.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
import { Injectable } from '@nestjs/common'
import { ServerInfoModel } from './models/server-info.model'
import { Injectable, HttpService } from '@nestjs/common'
import { Observable } from 'rxjs'
import { map } from 'rxjs/operators'
import { AxiosResponse } from 'axios'
import { BandwagonParams } from './interfaces/bandwagon-params.interface'
import { ServiceInfo } from './interfaces/service-info.interface'
import { UsageStats } from './interfaces/usage-stats.interface'
import { ConfigService } from '../config/config.service'
import { BANDWAGON_SERVICE_INFO_URL, BANDWAGON_USAGE_STATS_URL } from '../shared/constants'

@Injectable()
export class BandwagonService {
public async getServiceInfo(): Promise<ServerInfoModel[]> {
return {} as ServerInfoModel[]
private readonly params: BandwagonParams

constructor(private readonly httpService: HttpService, configService: ConfigService) {
this.httpService = httpService

const { BANDWAGON_SECRET_KEY, BANDWAGON_SERVER_ID } = configService.getBandwagonKeys()

this.params = { veid: BANDWAGON_SERVER_ID, api_key: BANDWAGON_SECRET_KEY }
}

public getServiceInfo(): Observable<AxiosResponse<ServiceInfo>> {
return this.httpService
.get(BANDWAGON_SERVICE_INFO_URL, { params: this.params })
.pipe(map(response => response.data))
}

public async getUsageStats(): Promise<ServerInfoModel[]> {
return {} as ServerInfoModel[]
public getUsageStats(): Observable<AxiosResponse<UsageStats>> {
return this.httpService
.get(BANDWAGON_USAGE_STATS_URL, { params: this.params })
.pipe(map(response => response.data.data))
}
}
4 changes: 4 additions & 0 deletions src/bandwagon/interfaces/bandwagon-params.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface BandwagonParams {
veid: string
api_key: string
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface ServerInfo {
export interface ServiceInfo {
vm_type: string
ve_status: string
ve_mac1: string
Expand Down
Loading

0 comments on commit dc249d5

Please sign in to comment.