Download src/controllers/userController.ts from ItsMa8di/idbot: direct link, hf CLI and curl.
- Browser
- Download file 931 Bytes
-
https://huggingface.co/spaces/ItsMa8di/idbot/resolve/main/src/controllers/userController.ts
- Command line
-
hf download hf://spaces/ItsMa8di/idbot/src/controllers/userController.ts
-
curl -L -o userController.ts https://huggingface.co/spaces/ItsMa8di/idbot/resolve/main/src/controllers/userController.ts
931 Bytes
| import { Number } from "mongoose"; | |
| import { IUser, UserModel } from "../models/User"; | |
| export class UserController { | |
| static async create(user: IUser): Promise<void> { | |
| try { | |
| await UserModel.create(user); | |
| } catch (e) { | |
| console.error(e); | |
| } | |
| } | |
| static async getByUserid(userid: number): Promise<IUser | undefined> { | |
| try { | |
| const foundedUser = await UserModel.findOne({ userid }); | |
| return foundedUser?.toJSON(); | |
| } catch (e) { | |
| console.error(e); | |
| return undefined; | |
| } | |
| } | |
| static async updateByUserid(userid: number, user: IUser): Promise<void> { | |
| try { | |
| const updatedUser = await UserModel.findOneAndUpdate({ userid }, user); | |
| } catch (e) { | |
| console.error(e); | |
| return; | |
| } | |
| } | |
| static async removeByUserid(userid: Number): Promise<void> { | |
| try { | |
| await UserModel.deleteOne({ userid }); | |
| } catch (e) { | |
| console.error(e); | |
| } | |
| } | |
| } | |