4.6.7-alpha commit (#743)

Co-authored-by: Archer <545436317@qq.com>
Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
This commit is contained in:
Archer
2024-01-19 11:17:28 +08:00
committed by GitHub
parent 8ee7407c4c
commit c031e6dcc9
324 changed files with 8509 additions and 4757 deletions

View File

@@ -1,6 +1,6 @@
import { UserType } from '@fastgpt/global/support/user/type';
import { MongoUser } from './schema';
import { getTeamInfoByTmbId, getUserDefaultTeam } from './team/controller';
import { getTmbInfoByTmbId, getUserDefaultTeam } from './team/controller';
import { ERROR_ENUM } from '@fastgpt/global/common/error/errorCode';
import { UserErrEnum } from '@fastgpt/global/common/error/code/user';
@@ -21,16 +21,16 @@ export async function getUserDetail({
tmbId?: string;
userId?: string;
}): Promise<UserType> {
const team = await (async () => {
const tmb = await (async () => {
if (tmbId) {
return getTeamInfoByTmbId({ tmbId });
return getTmbInfoByTmbId({ tmbId });
}
if (userId) {
return getUserDefaultTeam({ userId });
}
return Promise.reject(ERROR_ENUM.unAuthorization);
})();
const user = await MongoUser.findById(team.userId);
const user = await MongoUser.findById(tmb.userId);
if (!user) {
return Promise.reject(ERROR_ENUM.unAuthorization);
@@ -44,7 +44,7 @@ export async function getUserDetail({
timezone: user.timezone,
promotionRate: user.promotionRate,
openaiAccount: user.openaiAccount,
team
team: tmb
};
}

View File

@@ -56,9 +56,18 @@ const UserSchema = new Schema({
timezone: {
type: String,
default: 'Asia/Shanghai'
},
lastLoginTmbId: {
type: Schema.Types.ObjectId
}
});
try {
UserSchema.index({ createTime: -1 });
} catch (error) {
console.log(error);
}
export const MongoUser: Model<UserModelSchema> =
models[userCollectionName] || model(userCollectionName, UserSchema);
MongoUser.syncIndexes();

View File

@@ -8,7 +8,7 @@ import {
import { MongoTeamMember } from './teamMemberSchema';
import { MongoTeam } from './teamSchema';
async function getTeam(match: Record<string, any>): Promise<TeamItemType> {
async function getTeamMember(match: Record<string, any>): Promise<TeamItemType> {
const tmb = (await MongoTeamMember.findOne(match).populate('teamId')) as TeamMemberWithTeamSchema;
if (!tmb) {
@@ -31,11 +31,11 @@ async function getTeam(match: Record<string, any>): Promise<TeamItemType> {
};
}
export async function getTeamInfoByTmbId({ tmbId }: { tmbId: string }) {
export async function getTmbInfoByTmbId({ tmbId }: { tmbId: string }) {
if (!tmbId) {
return Promise.reject('tmbId or userId is required');
}
return getTeam({
return getTeamMember({
_id: new Types.ObjectId(tmbId),
status: notLeaveStatus
});
@@ -45,7 +45,7 @@ export async function getUserDefaultTeam({ userId }: { userId: string }) {
if (!userId) {
return Promise.reject('tmbId or userId is required');
}
return getTeam({
return getTeamMember({
userId: new Types.ObjectId(userId),
defaultTeam: true
});

View File

@@ -24,11 +24,11 @@ const TeamSchema = new Schema({
},
balance: {
type: Number,
default: 2 * PRICE_SCALE
default: 0
},
maxSize: {
type: Number,
default: 5
default: 3
},
limit: {
lastExportDatasetTime: {
@@ -41,7 +41,7 @@ const TeamSchema = new Schema({
});
try {
TeamSchema.index({ lastDatasetBillTime: -1 });
// TeamSchema.index({ createTime: -1 });
} catch (error) {
console.log(error);
}