mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-21 10:50:14 +01:00
🔧 refactor: Update Group Schema to use TypeScript and import from data-schemas
This commit is contained in:
parent
2fd04b6d65
commit
4448c13684
4 changed files with 47 additions and 43 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
const mongoose = require('mongoose');
|
const mongoose = require('mongoose');
|
||||||
const groupSchema = require('~/models/schema/groupSchema');
|
const { groupSchema } = require('@librechat/data-schemas');
|
||||||
|
|
||||||
const Group = mongoose.model('Group', groupSchema);
|
const Group = mongoose.model('Group', groupSchema);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
const mongoose = require('mongoose');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {Object} MongoGroup
|
|
||||||
* @property {ObjectId} [_id] - MongoDB Document ID
|
|
||||||
* @property {string} name - The group's name
|
|
||||||
* @property {string} [description] - A brief description of the group
|
|
||||||
* @property {string} [externalId] - External identifier for the group (required for non-local groups)
|
|
||||||
* @property {string} provider - The provider of the group. Defaults to 'local'. For external groups (e.g., 'openid') the externalId is required.
|
|
||||||
* @property {Date} [createdAt] - Date when the group was created (added by timestamps)
|
|
||||||
* @property {Date} [updatedAt] - Date when the group was last updated (added by timestamps)
|
|
||||||
*/
|
|
||||||
const groupSchema = mongoose.Schema(
|
|
||||||
{
|
|
||||||
name: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
unique: true,
|
|
||||||
},
|
|
||||||
description: {
|
|
||||||
type: String,
|
|
||||||
},
|
|
||||||
externalId: {
|
|
||||||
type: String,
|
|
||||||
unique: true,
|
|
||||||
required: function () {
|
|
||||||
return this.provider !== 'local';
|
|
||||||
},
|
|
||||||
},
|
|
||||||
provider: {
|
|
||||||
type: String,
|
|
||||||
required: true,
|
|
||||||
default: 'local',
|
|
||||||
enum: ['local', 'openid'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
{ timestamps: true },
|
|
||||||
);
|
|
||||||
|
|
||||||
module.exports = groupSchema;
|
|
||||||
39
packages/data-schemas/src/schema/group.ts
Normal file
39
packages/data-schemas/src/schema/group.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
import { Schema, Document } from 'mongoose';
|
||||||
|
|
||||||
|
export interface IGroup extends Document {
|
||||||
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
externalId?: string;
|
||||||
|
provider: 'local' | 'openid';
|
||||||
|
createdAt?: Date;
|
||||||
|
updatedAt?: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
const groupSchema = new Schema<IGroup>(
|
||||||
|
{
|
||||||
|
name: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
unique: true,
|
||||||
|
},
|
||||||
|
description: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
|
externalId: {
|
||||||
|
type: String,
|
||||||
|
unique: true,
|
||||||
|
required: function (this: IGroup) {
|
||||||
|
return this.provider !== 'local';
|
||||||
|
},
|
||||||
|
},
|
||||||
|
provider: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
default: 'local',
|
||||||
|
enum: ['local', 'openid'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ timestamps: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
export default groupSchema;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Schema, Document } from 'mongoose';
|
import { Schema, Document, Types } from 'mongoose';
|
||||||
import { SystemRoles } from 'librechat-data-provider';
|
import { SystemRoles } from 'librechat-data-provider';
|
||||||
|
|
||||||
export interface IUser extends Document {
|
export interface IUser extends Document {
|
||||||
|
|
@ -18,6 +18,7 @@ export interface IUser extends Document {
|
||||||
discordId?: string;
|
discordId?: string;
|
||||||
appleId?: string;
|
appleId?: string;
|
||||||
plugins?: unknown[];
|
plugins?: unknown[];
|
||||||
|
groups?: Types.ObjectId[];
|
||||||
twoFactorEnabled?: boolean;
|
twoFactorEnabled?: boolean;
|
||||||
totpSecret?: string;
|
totpSecret?: string;
|
||||||
backupCodes?: Array<{
|
backupCodes?: Array<{
|
||||||
|
|
@ -135,6 +136,11 @@ const User = new Schema<IUser>(
|
||||||
plugins: {
|
plugins: {
|
||||||
type: Array,
|
type: Array,
|
||||||
},
|
},
|
||||||
|
groups: {
|
||||||
|
type: [Schema.Types.ObjectId],
|
||||||
|
ref: 'Group',
|
||||||
|
default: [],
|
||||||
|
},
|
||||||
twoFactorEnabled: {
|
twoFactorEnabled: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue