344 lines
8.3 KiB
TypeScript
344 lines
8.3 KiB
TypeScript
import { ISession } from "../Session.model";
|
|
import { IUserDocument } from "./Users.Adapter.Mongoose";
|
|
|
|
export type SignUpParams = {
|
|
email: string;
|
|
password: string;
|
|
lastName: string;
|
|
firstName: string;
|
|
phoneCountryCode?: string;
|
|
phoneAreaCode: string;
|
|
phoneNumber: string;
|
|
};
|
|
|
|
export type UpdateUserParams = {
|
|
id: string;
|
|
userName?: string;
|
|
email?: string;
|
|
firstName?: string;
|
|
lastName?: string;
|
|
street?: string;
|
|
streetNumber?: string;
|
|
builingFloor?: string;
|
|
buildingApartament?: string;
|
|
block?: string; //barrio o localidad
|
|
city?: string;
|
|
state?: string;
|
|
country?: string;
|
|
zipCode?: string;
|
|
phoneCountryCode?: string;
|
|
phoneAreaCode?: string;
|
|
phoneNumber?: string;
|
|
verificated?: boolean;
|
|
sessionUser: string;
|
|
external_id?: string;
|
|
external_service?: string;
|
|
};
|
|
|
|
export type LoginParams = {
|
|
email: string;
|
|
password: string;
|
|
};
|
|
|
|
export type VerificationUserParams = LoginParams & {
|
|
verificationCode: string;
|
|
};
|
|
|
|
export type LoginByTokenParams = {
|
|
token: string;
|
|
};
|
|
|
|
export type LoginByGoogleParams = {
|
|
token: string;
|
|
};
|
|
|
|
export type ChangePasswordParams = {
|
|
oldPassword: string;
|
|
newPassword: string;
|
|
sessionUser: string;
|
|
};
|
|
|
|
export type SetUserFileParams = {
|
|
sessionUser: string;
|
|
file: Express.Multer.File;
|
|
};
|
|
|
|
export type FindUsersParams = {
|
|
_id?: string;
|
|
email?: string;
|
|
firstName?: string;
|
|
lastName?: string;
|
|
external_id?: string;
|
|
external_service?: string;
|
|
sessionUser?: string;
|
|
};
|
|
|
|
export interface IGoogleData {
|
|
id: string;
|
|
email: string;
|
|
name: string;
|
|
picture: string;
|
|
}
|
|
|
|
export interface IUserView {
|
|
id: string;
|
|
email: string;
|
|
firstName?: string;
|
|
lastName?: string;
|
|
fullName?: string;
|
|
avatar?: string;
|
|
phoneNumber?: string;
|
|
phoneCountryCode?: string;
|
|
phoneAreaCode?: string;
|
|
formattedPhoneNumber?: string;
|
|
street?: string;
|
|
streetNumber?: string;
|
|
builingFloor?: string;
|
|
buildingApartament?: string;
|
|
block?: string;
|
|
city?: string;
|
|
state?: string;
|
|
country?: string;
|
|
zipCode?: string;
|
|
}
|
|
|
|
export interface UserAssistanceInfo {
|
|
message: string;
|
|
email?: string;
|
|
fullName?: string;
|
|
verificated: boolean;
|
|
activationCode?: string;
|
|
recoveryCode?: string;
|
|
}
|
|
|
|
export interface CollaboratorView {
|
|
id: string;
|
|
email: string;
|
|
fullName: string;
|
|
avatar: string;
|
|
}
|
|
|
|
export type FindCollaboratorByEmailParams = {
|
|
email: string;
|
|
};
|
|
|
|
export type PaginateUsersParams = FindUsersParams & {
|
|
page: number;
|
|
limit: number;
|
|
};
|
|
|
|
export type PaginateUsersResults = {
|
|
data: IUser[];
|
|
page: number;
|
|
pages: number;
|
|
};
|
|
|
|
export type RecoveryAccountParams = {
|
|
email: string;
|
|
recoveryCode?: string;
|
|
newPassword?: string;
|
|
sendRecoveryCode: boolean;
|
|
};
|
|
|
|
export type DeleteUserParams = {
|
|
sessionUser: string;
|
|
};
|
|
|
|
export type SavePayerEmailParams = {
|
|
email: string;
|
|
sessionUser: string;
|
|
};
|
|
|
|
export type GetPayerEmailParams = {
|
|
sessionUser: string;
|
|
};
|
|
|
|
export type CheckUserPhoneParams = {
|
|
sessionUser: string;
|
|
};
|
|
|
|
export interface PayerEmailResult {
|
|
mpPayerEmail?: string;
|
|
}
|
|
|
|
export type SysAdminPaginateUsersParams = {
|
|
page: number;
|
|
limit: number;
|
|
name?: string;
|
|
lastName?: string;
|
|
email?: string;
|
|
isVerified?: boolean;
|
|
createdFrom?: string;
|
|
createdTo?: string;
|
|
sortBy?: "name" | "createdAt";
|
|
sortOrder?: "asc" | "desc";
|
|
};
|
|
|
|
export type SysAdminUpdateProfileParams = {
|
|
userId: string;
|
|
firstName?: string;
|
|
lastName?: string;
|
|
street?: string;
|
|
streetNumber?: string;
|
|
builingFloor?: string;
|
|
buildingApartament?: string;
|
|
block?: string;
|
|
city?: string;
|
|
state?: string;
|
|
country?: string;
|
|
zipCode?: string;
|
|
phoneCountryCode?: string;
|
|
phoneAreaCode?: string;
|
|
phoneNumber?: string;
|
|
};
|
|
|
|
export type SysAdminSetVerifiedParams = {
|
|
userId: string;
|
|
isVerified: boolean;
|
|
};
|
|
|
|
export type SysAdminDeleteUserParams = {
|
|
userId: string;
|
|
};
|
|
|
|
export type SysAdminOrganizationsStatusParams = {
|
|
userId: string;
|
|
};
|
|
|
|
export type SysAdminUserSubscriptionDetailsParams = {
|
|
userId: string;
|
|
};
|
|
|
|
export type SysAdminExtendUserSubscriptionMode = "add_months" | "set_end_date";
|
|
|
|
export type SysAdminExtendUserSubscriptionParams = {
|
|
userId: string;
|
|
mode: SysAdminExtendUserSubscriptionMode;
|
|
months?: 1 | 2;
|
|
endDate?: string;
|
|
reason?: string;
|
|
};
|
|
|
|
export type SysAdminExtendUserSubscriptionResult = {
|
|
userId: string;
|
|
subscriptionId: string;
|
|
previousEndDate: Date;
|
|
newEndDate: Date;
|
|
paymentId: string;
|
|
transactionId?: string;
|
|
};
|
|
|
|
export type SysAdminFinalizeUserSubscriptionParams = {
|
|
userId: string;
|
|
reason?: string;
|
|
};
|
|
|
|
export type SysAdminFinalizeUserSubscriptionResult = {
|
|
userId: string;
|
|
subscriptionId: string;
|
|
previousEndDate: Date;
|
|
newEndDate: Date;
|
|
};
|
|
|
|
export type SysAdminUserSubscriptionPayment = {
|
|
id: string;
|
|
subscriptionId: string;
|
|
amount: number;
|
|
paymentDate: Date;
|
|
paymentMethod?: string;
|
|
status: string;
|
|
transactionId?: string;
|
|
};
|
|
|
|
export type SysAdminUserSubscriptionDetailsResult = {
|
|
userId: string;
|
|
currentSubscription: {
|
|
id: string;
|
|
plan: {
|
|
id: string;
|
|
name: string;
|
|
code: string;
|
|
price: number;
|
|
} | null;
|
|
startDate: Date;
|
|
endDate: Date;
|
|
isActive: boolean;
|
|
mpStatus?: string;
|
|
billingMonths?: number;
|
|
pendingPaymentType?: "extension" | "upgrade";
|
|
pendingPaymentPreferenceId?: string;
|
|
lastPaymentStatus?: string;
|
|
} | null;
|
|
payments: SysAdminUserSubscriptionPayment[];
|
|
};
|
|
|
|
export type SysAdminUserOrganizationsResult = {
|
|
clientIn: { companyId: string; companyName: string }[];
|
|
collaboratorIn: { companyId: string; companyName: string }[];
|
|
};
|
|
|
|
|
|
export interface IUser {
|
|
id?: string;
|
|
password?: string;
|
|
email: string;
|
|
firstName?: string;
|
|
lastName?: string;
|
|
external_id?: string;
|
|
external_service?: string;
|
|
street?: string;
|
|
streetNumber?: string;
|
|
builingFloor?: string;
|
|
buildingApartament?: string;
|
|
block?: string;
|
|
city?: string;
|
|
state?: string;
|
|
country?: string;
|
|
zipCode?: string;
|
|
phoneCountryCode?: string;
|
|
phoneAreaCode?: string;
|
|
phoneNumber?: string;
|
|
verificated?: boolean;
|
|
verificationCode?: string;
|
|
recoveryCode?: string;
|
|
avatar?: string;
|
|
mpPayerEmail?: string;
|
|
lastLoginDate?: Date;
|
|
}
|
|
|
|
export interface IUsersAdapter {
|
|
create(user: IUser): Promise<IUser>;
|
|
delete(id: string): Promise<void>;
|
|
find(filters: FindUsersParams): Promise<IUser[]>;
|
|
findOne(filters: FindUsersParams): Promise<IUserDocument | null>;
|
|
paginate(filters: PaginateUsersParams): Promise<PaginateUsersResults>;
|
|
update(data: UpdateUserParams): Promise<void>;
|
|
sysAdminPaginate(filters: SysAdminPaginateUsersParams): Promise<PaginateUsersResults>;
|
|
}
|
|
|
|
export interface IUsersManager {
|
|
users: IUsersAdapter;
|
|
signUp(data: SignUpParams): Promise<IUser>;
|
|
login(data: LoginParams): Promise<ISession>;
|
|
loginByToken(data: LoginByTokenParams): Promise<ISession>;
|
|
changePassword(data: ChangePasswordParams): Promise<void>;
|
|
recoveryAccount(data: RecoveryAccountParams): Promise<void>;
|
|
updateUser(data: UpdateUserParams): Promise<void>;
|
|
setUserIcon(data: SetUserFileParams): Promise<void>;
|
|
findOne(data: FindUsersParams): Promise<IUserView | null>;
|
|
findByEmail(data: FindCollaboratorByEmailParams): Promise<CollaboratorView | null>;
|
|
getUserFullName(data: IUser): string;
|
|
deleteUser(data: DeleteUserParams): Promise<void>;
|
|
savePayerEmail(data: SavePayerEmailParams): Promise<void>;
|
|
getPayerEmail(data: GetPayerEmailParams): Promise<PayerEmailResult>;
|
|
checkUserPhone(data: CheckUserPhoneParams): Promise<boolean>;
|
|
getUserAssistanceInfo(data: FindUsersParams): Promise<UserAssistanceInfo>;
|
|
|
|
// SysAdmin Methods
|
|
sysAdminPaginateUsers(data: SysAdminPaginateUsersParams): Promise<PaginateUsersResults>;
|
|
sysAdminUpdateProfile(data: SysAdminUpdateProfileParams): Promise<void>;
|
|
sysAdminSetVerifiedStatus(data: SysAdminSetVerifiedParams): Promise<void>;
|
|
sysAdminDeleteUser(data: SysAdminDeleteUserParams): Promise<void>;
|
|
sysAdminOrganizationsStatus(data: SysAdminOrganizationsStatusParams): Promise<SysAdminUserOrganizationsResult>;
|
|
}
|