members
virtualGood
get()
parameters
- name : string - virtualGood's name
- playerId : string
return
- Promise[any]
import { virtualGood } from 'gamedrive';
const playerId = "5d6ede6a0ba62570afcedd3a"
virtualGood.get("name", playerId).then(data => {
const virtualGoodValue = {
name = data.name,
value = data.value,
}
console.log(virtualGoodValue)
}).catch( error =>{
//handle error
})
set()
parameters
- name : string - virtualGood's name
- playerId : string
- value : number - value to set
return
- Promise[any]
import { virtualGood } from 'gamedrive';
const playerId = "5d6ede6a0ba62570afcedd3a"
virtualGood.set("name", playerId, 999).then(data => {
const virtualGoodValue = {
name = data.name,
value = data.value,
}
console.log(virtualGoodValue)
}).catch( error =>{
//handle error
})
add()
parameters
- name : string - virtualGood's name
- playerId : string
- value : number - value to add
return
- Promise[any]
import { virtualGood } from 'gamedrive';
const playerId = "5d6ede6a0ba62570afcedd3a"
virtualGood.add("name", playerId, 1).then(data => {
const virtualGoodValue = {
name = data.name,
value = data.value,
}
console.log(virtualGoodValue)
}).catch( error =>{
//handle error
})
customData
Pass customData's name to first parameter of query functions and pass other paremeters by follow mongoose's Model apis (https://mongoosejs.com/docs/api/model.html).
import { customData } from 'gamedrive';
/* playerStatus's schema
{
"playerId": {
"type": "objectId",
"unique": true
},
"health": {
"type": "number",
"default": 50
},
"mana": {
"type": "number",
"default": 50
}
}
*/
customData.create("playerStatus", {
playerId: "5d6ede6a0ba62570afcedd3a",
health: 100,
mana: 100
}).then(data => {
//handle data
}).catch(error => {
//handle error
})
query functions
create(name: string, docs: any, options: any): Promise<any>
findOne(name: string, conditions: any, projection: any, options: any): Promise<any>
insertMany(name: string, docs: any[], options: any): Promise<any[]>
updateOne(name: string, filter: any, update: any, options: any): Promise<MongooseUpdateResult>
updateMany(name: string, filter: any, update: any, options: any): Promise<MongooseUpdateResult>
//max 200 row
find(name: string, filter: any, projection: any, options: any): Promise<any[]>
findOneAndUpdate(name: string, conditions: any, update: any, options: any): Promise<any>
findOneAndDelete(name: string, conditions: any, options: any): Promise<any>
findById(name: string, _id: any, projection: any, options: any): Promise<any>
findByIdAndUpdate(name: string, _id: any, update: any, options: any): Promise<any>
findByIdAndDelete(name: string, _id: any, options: any): Promise<any>
countDocuments(name: string, filter: any): Promise<number>
estimatedDocumentCount(name: string, options: any): Promise<number>
deleteMany(name: string, conditions: any, options: any): Promise<any>
player
findById()
parameters
- playerId : string
return
- Promise[any]
import { player } from 'gamedrive';
const playerId = "5d6ede6a0ba62570afcedd3a"
player.findById(playerId).then(data => {
//handle data
/*
{
_id,
name,
numberId,
profilePictureUrl
}
*/
}).catch( error =>{
//handle error
})
findByNumberId()
parameters
- numberId : number
return
- Promise[any]
import { player } from 'gamedrive';
const playerNumberId = 0000000001
player.findByNumberId(playerNumberId).then(data => {
//handle data
/*
{
_id,
name,
numberId,
profilePictureUrl
}
*/
}).catch( error =>{
//handle error
})
findAccountById()
parameters
- playerId : string
return
- Promise[any]
import { player } from 'gamedrive';
const playerId = "5d6ede6a0ba62570afcedd3a"
player.findAccountById(playerId).then(data => {
//handle data
/*
{
devices,
socialAccounts
}
*/
}).catch( error =>{
//handle error
})
Request
Class of first argument of endpoint which storing data of the request send from client
playerId
Id of player who send the request
import { Request, Response } from 'gamedrive';
export default function (request: Request, response: Response) {
const playerId = request.playerId//some value like "5d6ede6a0ba62570afcedd3a"
console.log("playerId:", playerId)
}
args
Array of argument passed to the endpoint
import { Request, Response } from 'gamedrive';
export default function (request: Request, response: Response) {
const args : any[] = request.args//some value like "5d6ede6a0ba62570afcedd3a"
//request.args.length will equal 0 if no argument passed
console.log("args:", args)
}
Response
Class of second argument of endpoint which storing functions to send response to client
send()
Send response back to client
import { Request, Response } from 'gamedrive';
export default function (request: Request, response: Response) {
const args : any[] = request.args//some value like "5d6ede6a0ba62570afcedd3a"
//request.args.length will equal 0 if no argument passed
response.send({message: "Hello world"})
}
sendError()
Send error response back to client
import { Request, Response } from 'gamedrive';
export default function (request: Request, response: Response) {
//you can call sendError in 2 forms
response.sendError("message")
response.sendError("CODE", "message")//send CODE and message
}
webRequest
Class of second argument of endpoint which storing functions to send response to client https://github.com/axios/axios "axios": "^0.27.2"
webReqest.get(url[, config]) webReqest.delete(url[, config]) webReqest.head(url[, config]) webReqest.options(url[, config]) webReqest.post(url[, data[, config]]) webReqest.put(url[, data[, config]]) webReqest.patch(url[, data[, config]])
get()
Send response back to client
import { Request, Response } from 'gamedrive';
export default function (request: Request, response: Response) {
const args : any[] = request.args//some value like "5d6ede6a0ba62570afcedd3a"
//request.args.length will equal 0 if no argument passed
response.send({message: "Hello world"})
}
sendError()
Send error response back to client
import { Request, Response } from 'gamedrive';
export default function (request: Request, response: Response) {
//you can call sendError in 2 forms
response.sendError("message")
response.sendError("CODE", "message")//send CODE and message
}