perf: invite member code (#4118)

* perf: invite member code

* fix: ts
This commit is contained in:
Archer
2025-03-12 14:35:38 +08:00
committed by archer
parent a9e5017492
commit 7eda599181
20 changed files with 284 additions and 342 deletions

View File

@@ -1,3 +0,0 @@
export function isForbidden({ expires, forbidden }: { expires: Date; forbidden?: boolean }) {
return forbidden || new Date(expires) < new Date();
}

View File

@@ -16,17 +16,13 @@ const InvitationSchema = new Schema({
required: true
},
usedTimesLimit: {
type: Number
},
forbidden: {
type: Boolean
},
expires: {
type: Date
},
description: {
type: String
type: Number,
default: 1,
enum: [1, -1]
},
forbidden: Boolean,
expires: Date,
description: String,
members: {
type: [String],
default: []
@@ -40,10 +36,9 @@ InvitationSchema.virtual('team', {
justOne: true
});
InvitationSchema.index({ expires: 1 }, { expireAfterSeconds: 30 * 24 * 60 * 60 });
try {
InvitationSchema.index({ teamId: 1 }, { background: true });
InvitationSchema.index({ teamId: 1 });
InvitationSchema.index({ expires: 1 }, { expireAfterSeconds: 30 * 24 * 60 * 60 });
} catch (error) {
console.log(error);
}

View File

@@ -23,7 +23,7 @@ export type InvitationLinkExpiresType = '30m' | '7d' | '1y';
export type InvitationLinkCreateType = {
description: string;
expires: InvitationLinkExpiresType;
usedTimesLimit: number;
usedTimesLimit: 1 | -1;
};
export type InvitationLinkUpdateType = Partial<
Omit<InvitationSchemaType, 'members' | 'teamId' | '_id'>