➕ Add Groups to SVAPI
This commit is contained in:
parent
8eb370fcaf
commit
a986fbe2a7
|
@ -2,7 +2,9 @@
|
|||
// Written by Brendan Lane - https://brndnln.dev/
|
||||
|
||||
import User from './modules/User'
|
||||
import Group from './modules/Group'
|
||||
|
||||
export {
|
||||
User
|
||||
User,
|
||||
Group
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
// Written by Brendan Lane - https://brndnln.dev/
|
||||
|
||||
import axios from 'axios'
|
||||
import { AuthEntity, CreditAmount, GroupMember, PaymentEntity } from './types/Types'
|
||||
|
||||
const groupURL = 'https://api.spookvooper.com/group'
|
||||
const ecoURL = 'https://api.spookvooper.com/eco'
|
||||
|
@ -10,6 +11,150 @@ class Group {
|
|||
private accountid: string
|
||||
|
||||
constructor (svid: string) {
|
||||
if (!svid.startsWith('g-')) {
|
||||
throw new Error('A group SVID must start with a \'g-\' to comply with the latest API changes')
|
||||
}
|
||||
|
||||
this.accountid = svid
|
||||
}
|
||||
|
||||
public async getGroup (): Promise<any> {
|
||||
return await new Promise((resolve, reject) => {
|
||||
axios.get(`${groupURL}/getGroup`, {
|
||||
params: {
|
||||
svid: this.accountid
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
public async sendCredits (amount: CreditAmount, to: PaymentEntity, reason: string, auth: AuthEntity): Promise<any> {
|
||||
if (typeof to === 'string') {
|
||||
return await new Promise((resolve, reject) => {
|
||||
axios.get(`${ecoURL}/sendTransactionByIds`, {
|
||||
params: {
|
||||
from: this.accountid,
|
||||
to: to,
|
||||
amount: amount,
|
||||
auth: auth.apikey,
|
||||
detail: reason
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
} else if (typeof to === 'object') {
|
||||
return await new Promise((resolve, reject) => {
|
||||
axios.get(`${ecoURL}/sendTransactionByIds`, {
|
||||
params: {
|
||||
from: this.accountid,
|
||||
to: to.svid,
|
||||
amount: amount,
|
||||
auth: auth.apikey,
|
||||
detail: reason
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
} else {
|
||||
throw new Error('The \'to\' parameter must be a string or an object!')
|
||||
}
|
||||
}
|
||||
|
||||
public async doesGroupExist (): Promise<any> {
|
||||
return await new Promise((resolve, reject) => {
|
||||
axios.get(`${groupURL}/doesGroupExist`, {
|
||||
params: {
|
||||
svid: this.accountid
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
public async getGroupMembers (): Promise<any> {
|
||||
return await new Promise((resolve, reject) => {
|
||||
axios.get(`${groupURL}/getGroupMembers`, {
|
||||
params: {
|
||||
svid: this.accountid
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
public async hasGroupPermission (user: GroupMember, permission: string): Promise<any> {
|
||||
if (typeof user === 'string') {
|
||||
return await new Promise((resolve, reject) => {
|
||||
axios.get(`${groupURL}/hasGroupPermission`, {
|
||||
params: {
|
||||
svid: this.accountid,
|
||||
usersvid: user,
|
||||
permission: permission
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
} else if (typeof user === 'object') {
|
||||
return await new Promise((resolve, reject) => {
|
||||
axios.get(`${groupURL}/hasGroupPermission`, {
|
||||
params: {
|
||||
svid: this.accountid,
|
||||
usersvid: user.svid,
|
||||
permission: permission
|
||||
}
|
||||
})
|
||||
.then((response) => {
|
||||
resolve(response.data)
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
} else {
|
||||
throw new Error('Argument \'user\' must either be a string or an object!')
|
||||
}
|
||||
}
|
||||
|
||||
public get svid (): string {
|
||||
return this.accountid
|
||||
}
|
||||
|
||||
public set svid (svid: string) {
|
||||
if (!svid.startsWith('g-')) {
|
||||
throw new Error('A group SVID must start with a \'g-\' to comply with the latest API changes')
|
||||
}
|
||||
|
||||
this.accountid = svid
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,3 +6,5 @@ import { EntityUser } from './../interfaces/Interfaces'
|
|||
export type CreditAmount = string | number
|
||||
export type PaymentEntity = string | EntityUser
|
||||
export type SVStockTicker = 'B' | 'IDE' | 'NEWS' | 'POT' | 'TECH' | 'TYCO' | 'VC' | 'VNB' | 'VU' | 'X'
|
||||
export type AuthEntity = EntityUser
|
||||
export type GroupMember = string | EntityUser
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
// SpookVooper API - src/main.ts
|
||||
// Written by Brendan Lane - https://brndnln.dev/
|
||||
import User from './modules/User';
|
||||
import Group from './modules/Group';
|
||||
export { User, Group };
|
|
@ -0,0 +1,14 @@
|
|||
import { AuthEntity, CreditAmount, GroupMember, PaymentEntity } from './types/Types'
|
||||
declare class Group {
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-readonly
|
||||
private accountid
|
||||
constructor (svid: string)
|
||||
getGroup (): Promise<any>
|
||||
sendCredits (amount: CreditAmount, to: PaymentEntity, reason: string, auth: AuthEntity): Promise<any>
|
||||
doesGroupExist (): Promise<any>
|
||||
getGroupMembers (): Promise<any>
|
||||
hasGroupPermission (user: GroupMember, permission: string): Promise<any>
|
||||
get svid (): string
|
||||
set svid (svid: string)
|
||||
}
|
||||
export default Group
|
|
@ -2,3 +2,5 @@ import { EntityUser } from './../interfaces/Interfaces'
|
|||
export declare type CreditAmount = string | number
|
||||
export declare type PaymentEntity = string | EntityUser
|
||||
export declare type SVStockTicker = 'B' | 'IDE' | 'NEWS' | 'POT' | 'TECH' | 'TYCO' | 'VC' | 'VNB' | 'VU' | 'X'
|
||||
export declare type AuthEntity = EntityUser
|
||||
export declare type GroupMember = string | EntityUser
|
||||
|
|
Loading…
Reference in New Issue