Skip to content

Commit

Permalink
feat: extend user profile model
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgenyWas committed Jun 10, 2024
1 parent 04027bc commit af9aea0
Showing 1 changed file with 51 additions and 62 deletions.
113 changes: 51 additions & 62 deletions server/models/user/profile.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,62 @@ import { Schema, model } from 'mongoose';
import { AUTH_PROVIDERS, MAX_USER_SOCIALS, MIN_USER_NAME_LENGTH } from '~/configs/properties';
import { emailValidator, passwordValidator, base64Validator } from '~/utils/validators';

const schema = new Schema({
name: {
type: String,
required: true,
minLength: MIN_USER_NAME_LENGTH,
},
email: {
type: String,
required: true,
immutable: true,
validate: {
validator: (value: string) => emailValidator.safeParse(value).success,
const schema = new Schema(
{
name: {
type: String,
required: true,
minLength: MIN_USER_NAME_LENGTH,
},
},
password: {
type: String,
validate: {
validator: (value: string) => passwordValidator.safeParse(value).success,
email: {
type: String,
required: true,
immutable: true,
validate: {
validator: (value: string) => emailValidator.safeParse(value).success,
},
},
},
avatar: {
type: String,
validate: {
validator: (value?: string) => !base64Validator.safeParse(value).success,
message: 'Avatar in base64 format is forbidden.',
password: {
type: String,
validate: {
validator: (value: string) => passwordValidator.safeParse(value).success,
},
},
default: '',
},
description: {
type: String,
default: '',
},
address: {
type: String,
default: '',
},
phone: {
type: String,
default: '',
},
socials: {
type: Array,
validate: {
validator: (value: Array<string>) => value.length <= MAX_USER_SOCIALS,
message: `The maximum number of socials is ${MAX_USER_SOCIALS}`,
avatar: {
type: String,
validate: {
validator: (value?: string) => !base64Validator.safeParse(value).success,
message: 'Avatar in base64 format is forbidden.',
},
default: '',
},
description: {
type: String,
default: '',
},
address: {
type: String,
default: '',
},
phone: {
type: String,
default: '',
},
socials: {
type: Array,
validate: {
validator: (value: Array<string>) => value.length <= MAX_USER_SOCIALS,
message: `The maximum number of socials is ${MAX_USER_SOCIALS}`,
},
default: () => Array(MAX_USER_SOCIALS).fill(''),
},
auth_provider: {
type: String,
enum: Object.values(AUTH_PROVIDERS),
},
default: () => Array(MAX_USER_SOCIALS).fill(''),
},
auth_provider: {
type: String,
enum: Object.values(AUTH_PROVIDERS),
},
createdAt: {
type: Date,
immutable: true,
default: () => new Date(),
},
updatedAt: {
type: Date,
default: () => new Date(),
},
});

schema.pre('save', function (next) {
this.updatedAt = new Date();
next();
});
{ timestamps: true },
);

const Profile = model('user_profile', schema);

Expand Down

0 comments on commit af9aea0

Please sign in to comment.