kafka-consumer-nestjs/src/processor/user.ts

35 lines
815 B
TypeScript

import { User } from 'src/dto/user';
export class UserProcessor {
user: User;
users: User[] = [];
result: { youngs: number } = {
youngs: 0,
};
isYoungUser() {
console.log(this.user.birthdate);
return new Date(this.user.birthdate).getFullYear() >= 1998;
}
isYahoo() {
return this.user.email.includes('@yahoo');
}
isGmail() {
return this.user.email.includes('@gamil');
}
process(user: User) {
this.user = user;
this.users.push(user);
if (this.isYoungUser()) {
this.result.youngs += 1;
}
// if (this.isGmail()) {
// thiss.result.mail.find((m) => m.name == 'gmail').qt += 1;
// }
// if (this.isYahoo()) {
// this.result.mail.find((m) => m.name == 'yahoo').qt += 1;
// }
console.log(this.users.length, this.result);
}
}