From fc67ec1403845dd4ba60cf8e64e52f1da86d7a30 Mon Sep 17 00:00:00 2001 From: Behzad Rabiei <53224485+Behzad-rabiei@users.noreply.github.com> Date: Thu, 21 Dec 2023 11:38:45 +0330 Subject: [PATCH 1/3] [FIXBUG]: change user type from snowflake to objectid --- README.md | 2 +- package.json | 2 +- src/interfaces/Token.interface.ts | 6 +++--- src/models/schemas/Token.schema.ts | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8f704ef..4ee950e 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ memberactivities { ```ts Token { token: string, - user: Snowflake, + user: Types.ObjectId, type: string, expires: Date, blacklisted?: boolean diff --git a/package.json b/package.json index 187f7cf..ad5a771 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@togethercrew.dev/db", - "version": "3.0.18", + "version": "3.0.19", "description": "All interactions with DB", "main": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/src/interfaces/Token.interface.ts b/src/interfaces/Token.interface.ts index d18b463..14c3c02 100644 --- a/src/interfaces/Token.interface.ts +++ b/src/interfaces/Token.interface.ts @@ -1,9 +1,9 @@ -import { type Snowflake } from 'discord.js'; -import { type Model } from 'mongoose'; +import { type Model, type Types } from 'mongoose'; + export interface IToken { token: string; - user: Snowflake; + user: Types.ObjectId; type: string; expires: Date; blacklisted?: boolean; diff --git a/src/models/schemas/Token.schema.ts b/src/models/schemas/Token.schema.ts index 62fec3b..7af94ec 100644 --- a/src/models/schemas/Token.schema.ts +++ b/src/models/schemas/Token.schema.ts @@ -11,7 +11,7 @@ const tokenSchema = new Schema( index: true, }, user: { - type: String, + type: Schema.Types.ObjectId, ref: 'User', required: true, }, From 4bddc64a20c10980bb3a11b706ca215696a0db29 Mon Sep 17 00:00:00 2001 From: Behzad Rabiei <53224485+Behzad-rabiei@users.noreply.github.com> Date: Thu, 21 Dec 2023 11:41:15 +0330 Subject: [PATCH 2/3] [FORMAT] --- src/interfaces/Token.interface.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/interfaces/Token.interface.ts b/src/interfaces/Token.interface.ts index 14c3c02..438aaeb 100644 --- a/src/interfaces/Token.interface.ts +++ b/src/interfaces/Token.interface.ts @@ -1,6 +1,5 @@ import { type Model, type Types } from 'mongoose'; - export interface IToken { token: string; user: Types.ObjectId; From efc09a4ea15653e2ed99a772dbf865eb91231c9e Mon Sep 17 00:00:00 2001 From: Behzad Rabiei <53224485+Behzad-rabiei@users.noreply.github.com> Date: Thu, 21 Dec 2023 11:44:36 +0330 Subject: [PATCH 3/3] [TEST]: update tests --- __tests__/unit/models/token.model.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/__tests__/unit/models/token.model.test.ts b/__tests__/unit/models/token.model.test.ts index aa25fd1..e6feeea 100644 --- a/__tests__/unit/models/token.model.test.ts +++ b/__tests__/unit/models/token.model.test.ts @@ -1,5 +1,6 @@ import { Token } from '../../../src/models'; import { IToken } from '../../../src/interfaces'; +import { Types } from 'mongoose'; import moment from 'moment'; describe('Token model', () => { @@ -7,7 +8,7 @@ describe('Token model', () => { let token: IToken; beforeEach(() => { token = { - user: '1234', + user: new Types.ObjectId(), token: '4321', type: 'access', expires: moment('2022-02-01 08:30:26.127Z').toDate(),