move over to database service cause I forgot I made that
This commit is contained in:
@@ -2,6 +2,7 @@ import { Server, ServerUnaryCall, sendUnaryData } from '@grpc/grpc-js'
|
||||
import { ReflectionService } from '@grpc/reflection'
|
||||
import { loadSync } from '@grpc/proto-loader'
|
||||
import { MongoClient, Collection, Db } from 'mongodb'
|
||||
import { DatabaseService } from './database'
|
||||
|
||||
import {
|
||||
Character,
|
||||
@@ -17,12 +18,13 @@ import {
|
||||
export class CharacterService {
|
||||
reflectionService: ReflectionService
|
||||
characterManager: ICharacterManager
|
||||
databaseService: DatabaseService
|
||||
|
||||
mongoClient: MongoClient
|
||||
db: Db
|
||||
characterCollection: Collection
|
||||
// mongoClient: MongoClient
|
||||
// db: Db
|
||||
// characterCollection: Collection
|
||||
|
||||
constructor(mongoClient: MongoClient, dbName: string) {
|
||||
constructor(databaseService: DatabaseService) {
|
||||
this.reflectionService = new ReflectionService(
|
||||
loadSync('./src/proto/character.proto'),
|
||||
)
|
||||
@@ -32,9 +34,11 @@ export class CharacterService {
|
||||
getCharacter: this.getCharacterCall.bind(this),
|
||||
}
|
||||
|
||||
this.mongoClient = mongoClient
|
||||
this.db = this.mongoClient.db(dbName)
|
||||
this.characterCollection = this.db.collection('Characters')
|
||||
this.databaseService = databaseService
|
||||
|
||||
// this.mongoClient = mongoClient
|
||||
// this.db = this.mongoClient.db(dbName)
|
||||
// this.characterCollection = this.db.collection('Characters')
|
||||
}
|
||||
|
||||
addToServer(server: Server) {
|
||||
@@ -48,14 +52,16 @@ export class CharacterService {
|
||||
callback: sendUnaryData<Character>,
|
||||
) {
|
||||
|
||||
let newCharacter = await this.characterCollection
|
||||
.insertOne(call.request.characterData)
|
||||
.then((insertResult) => {
|
||||
console.log(insertResult)
|
||||
return this.characterCollection.findOne({
|
||||
_id: insertResult.insertedId,
|
||||
})
|
||||
})
|
||||
let newCharacter = await this.databaseService.insertCharacter(call.request.characterData)
|
||||
|
||||
// this.characterCollection
|
||||
// .insertOne(call.request.characterData)
|
||||
// .then((insertResult) => {
|
||||
// console.log(insertResult)
|
||||
// return this.characterCollection.findOne({
|
||||
// _id: insertResult.insertedId,
|
||||
// })
|
||||
// })
|
||||
|
||||
console.log(newCharacter)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user