gateway 코드 이식 중
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
import { Schema, model } from 'mongoose';
|
||||
|
||||
export type UserIDType = number;
|
||||
|
||||
const validOAuthTypeList = ['KAKAO', 'NONE'] as const;
|
||||
export type validOAuthType = typeof validOAuthTypeList[number];
|
||||
|
||||
const validServerActionTypeList = [
|
||||
'Update', 'UpdateByGitPath', 'ShowErrorLog',
|
||||
'CloseServer', 'OpenServer', 'StopAndResumeServer', 'OpenVote',
|
||||
] as const;
|
||||
export type ServerActionType = typeof validServerActionTypeList[number];
|
||||
|
||||
const validGatewayActionTypeList = [
|
||||
'Update', 'UpdateByGitPath', 'ShowErrorLog', 'ResetUserPassword', 'ChangeGatewayState', 'DeleteUser',
|
||||
] as const;
|
||||
|
||||
export type GatewayActionType = typeof validGatewayActionTypeList[number];
|
||||
|
||||
interface IUser {
|
||||
_id: UserIDType;
|
||||
|
||||
oauthID?: bigint;
|
||||
id: string;
|
||||
email: string;
|
||||
|
||||
oauthType: validOAuthType;
|
||||
oauthInfo?: object;
|
||||
tokenValidUntil?: Date;
|
||||
|
||||
userSalt: string;
|
||||
hashedPassword: string;
|
||||
|
||||
allowThirdPartyUse: boolean;
|
||||
|
||||
userName: string;
|
||||
allowServerAction?: Map<string, ServerActionType[]>;
|
||||
allowGatewayAction?: ServerActionType[];
|
||||
penalty?: Map<string, Date>;
|
||||
|
||||
picture?: string;
|
||||
useImgSvr?: boolean;
|
||||
|
||||
regDate: Date;
|
||||
deleteAfter?: Date;
|
||||
}
|
||||
|
||||
export const User = new Schema<IUser>({
|
||||
_id: { type: Number, required: true },
|
||||
|
||||
oauthID: { type: BigInt, required: false },
|
||||
id: { type: String, required: true },
|
||||
email: { type: String, required: true },
|
||||
|
||||
oauthType: { type: String, required: true, enum: validOAuthTypeList },
|
||||
oauthInfo: { type: Object, required: false },
|
||||
tokenValidUntil: { type: Date, required: false },
|
||||
|
||||
userSalt: { type: String, required: true },
|
||||
hashedPassword: { type: String, required: true },
|
||||
|
||||
allowThirdPartyUse: { type: Boolean, required: true },
|
||||
|
||||
userName: { type: String, required: true },
|
||||
allowServerAction: {
|
||||
type: Map, required: false, of: {
|
||||
type: Array,
|
||||
of: { type: String, enum: validServerActionTypeList }
|
||||
}
|
||||
},
|
||||
allowGatewayAction: {
|
||||
type: Array, required: false, of: {
|
||||
type: String, enum: validGatewayActionTypeList
|
||||
}
|
||||
},
|
||||
penalty: { type: Map, required: false, of: Date },
|
||||
|
||||
picture: { type: String, required: false },
|
||||
useImgSvr: { type: Boolean, required: false },
|
||||
|
||||
regDate: { type: Date, required: true },
|
||||
deleteAfter: { type: Date, required: false },
|
||||
}, { autoIndex: false, autoCreate: false })
|
||||
.index({ id: 1 }, { unique: true })
|
||||
.index({ email: 1 }, { unique: true })
|
||||
.index({ oauthID: 1 }, { unique: true, sparse: true })
|
||||
.index({ deleteAfter: 1 }) // 자동 삭제 아님!
|
||||
;
|
||||
|
||||
export default model<IUser>('User', User);
|
||||
Reference in New Issue
Block a user