From 9d6a484353c5c146e49bf4823aec6c76a9173b1a Mon Sep 17 00:00:00 2001 From: kaisr31sh62 Date: Tue, 12 Jul 2022 17:19:05 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B5=E3=82=A4=E3=83=B3=E3=82=A2=E3=83=83?= =?UTF-8?q?=E3=83=97=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/db.ts | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/library/db.ts b/library/db.ts index fb2549c..17c81c1 100644 --- a/library/db.ts +++ b/library/db.ts @@ -2,26 +2,41 @@ import { Avatar, Player, User } from "cello-core/core"; import { IAccountRepository, Identifier } from "cello-core/infrastructure"; import mongoose, { Schema, model, connect } from "mongoose"; -const UserSchema = new Schema({ email: String, password: String }, { timestamps: true }); +mongoose.connect( + "mongodb://ih4ciw4cadmin:ikZvgiIvLijUii4MfeJoXVmvfVCZZSqNtKNAkdLtCAMSjgzfKvXDGwK7T5nzIyXbZMfGanDDhchkI4twgT1xiA==@ih4ciw4cadmin.mongo.cosmos.azure.com:10255/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@ih4ciw4cadmin" +); -const UserModel = model("User", UserSchema); +const UserSchema = new mongoose.Schema({ email: String, password: String }, { timestamps: true }); +const QuestsSchema = new Schema({ + name: String, + category: Number, + exp_get: Number, +}); +const UserModel = mongoose.model("User", UserSchema); +const QuestsModel = mongoose.model("Quests", QuestsSchema); + +const modelToInsert = new UserModel(); export class AccountRepository implements IAccountRepository { getUser(id: Identifier): Promise { throw new Error("Method not implemented."); } registerNewUser(user: User): Promise { - mongoose.connect( - "mongodb://ih4ciw4cadmin:ikZvgiIvLijUii4MfeJoXVmvfVCZZSqNtKNAkdLtCAMSjgzfKvXDGwK7T5nzIyXbZMfGanDDhchkI4twgT1xiA==@ih4ciw4cadmin.mongo.cosmos.azure.com:10255/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@ih4ciw4cadmin" - ); - const modelToInsert = new UserModel(); - modelToInsert["email"] = user.email; - modelToInsert["password"] = user.password; + try { + modelToInsert["email"] = user.email; + modelToInsert["password"] = user.password; - modelToInsert.save(); - throw new Error("Method not implemented."); + modelToInsert.save(); + return Promise.resolve(); + } catch { + return Promise.reject("理由"); + } } + getUserPassword(id: Identifier): Promise { + const findQuests = async () => { + return await QuestsModel.find({}).select("category"); + }; throw new Error("Method not implemented."); } updateUserPassword(user: unknown, password: unknown): Promise {