Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: string trim set true for whole schema #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 56 additions & 50 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"helmet": "^4.1.1",
"jsonwebtoken": "^8.5.1",
"lodash": "^4.17.20",
"mongoose": "^5.10.11",
"mongoose": "^5.13.7",
"winston": "^3.3.3",
"winston-daily-rotate-file": "^4.5.0"
},
Expand Down
12 changes: 2 additions & 10 deletions src/database/model/ApiKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default interface ApiKey extends Document {
updatedAt?: Date;
}

Schema.Types.String.set('trim', true);
const schema = new Schema(
{
key: {
Expand All @@ -34,20 +35,11 @@ const schema = new Schema(
type: Schema.Types.Boolean,
default: true,
},
createdAt: {
type: Date,
required: true,
select: false,
},
updatedAt: {
type: Date,
required: true,
select: false,
},
},
{
versionKey: false,
},
);

schema.set('timestamps', true);
export const ApiKeyModel = model<ApiKey>(DOCUMENT_NAME, schema, COLLECTION_NAME);
18 changes: 3 additions & 15 deletions src/database/model/Blog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,18 @@ export default interface Blog extends Document {
updatedAt?: Date;
}

Schema.Types.String.set('trim', true);
const schema = new Schema(
{
title: {
type: Schema.Types.String,
required: true,
maxlength: 500,
trim: true,
},
description: {
type: Schema.Types.String,
required: true,
maxlength: 2000,
trim: true,
},
text: {
type: Schema.Types.String,
Expand All @@ -53,7 +52,7 @@ const schema = new Schema(
tags: [
{
type: Schema.Types.String,
trim: true,

uppercase: true,
},
],
Expand All @@ -67,14 +66,12 @@ const schema = new Schema(
type: Schema.Types.String,
required: false,
maxlength: 500,
trim: true,
},
blogUrl: {
type: Schema.Types.String,
required: true,
unique: true,
maxlength: 200,
trim: true,
},
likes: {
type: Schema.Types.Number,
Expand Down Expand Up @@ -127,16 +124,6 @@ const schema = new Schema(
required: true,
select: false,
},
createdAt: {
type: Date,
required: true,
select: false,
},
updatedAt: {
type: Date,
required: true,
select: false,
},
},
{
versionKey: false,
Expand All @@ -146,4 +133,5 @@ const schema = new Schema(
{ weights: { title: 3, description: 1 }, background: false },
);

schema.set('timestamps', true);
export const BlogModel = model<Blog>(DOCUMENT_NAME, schema, COLLECTION_NAME);
13 changes: 2 additions & 11 deletions src/database/model/Keystore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default interface Keystore extends Document {
updatedAt?: Date;
}

Schema.Types.String.set('trim', true);
const schema = new Schema(
{
client: {
Expand All @@ -32,16 +33,6 @@ const schema = new Schema(
type: Schema.Types.Boolean,
default: true,
},
createdAt: {
type: Date,
required: true,
select: false,
},
updatedAt: {
type: Date,
required: true,
select: false,
},
},
{
versionKey: false,
Expand All @@ -50,5 +41,5 @@ const schema = new Schema(

schema.index({ client: 1, primaryKey: 1 });
schema.index({ client: 1, primaryKey: 1, secondaryKey: 1 });

schema.set('timestamps', true);
export const KeystoreModel = model<Keystore>(DOCUMENT_NAME, schema, COLLECTION_NAME);
12 changes: 2 additions & 10 deletions src/database/model/Role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default interface Role extends Document {
updatedAt?: Date;
}

Schema.Types.String.set('trim', true);
const schema = new Schema(
{
code: {
Expand All @@ -28,20 +29,11 @@ const schema = new Schema(
type: Schema.Types.Boolean,
default: true,
},
createdAt: {
type: Date,
required: true,
select: false,
},
updatedAt: {
type: Date,
required: true,
select: false,
},
},
{
versionKey: false,
},
);

schema.set('timestamps', true);
export const RoleModel = model<Role>(DOCUMENT_NAME, schema, COLLECTION_NAME);
Loading