mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
feat(server): use user model (#9710)
This commit is contained in:
@@ -71,7 +71,7 @@ const ModelsSymbolProvider: ExistingProvider = {
|
||||
providers: [...Object.values(MODELS), ModelsProvider, ModelsSymbolProvider],
|
||||
exports: [ModelsProvider],
|
||||
})
|
||||
export class ModelModules {}
|
||||
export class ModelsModule {}
|
||||
|
||||
export * from './feature';
|
||||
export * from './page';
|
||||
|
||||
@@ -6,8 +6,6 @@ import {
|
||||
CryptoHelper,
|
||||
EmailAlreadyUsed,
|
||||
EventEmitter,
|
||||
type EventPayload,
|
||||
OnEvent,
|
||||
WrongSignInCredentials,
|
||||
WrongSignInMethod,
|
||||
} from '../base';
|
||||
@@ -248,55 +246,4 @@ export class UserModel extends BaseModel {
|
||||
async count() {
|
||||
return this.db.user.count();
|
||||
}
|
||||
|
||||
@OnEvent('user.updated')
|
||||
async onUserUpdated(user: EventPayload<'user.updated'>) {
|
||||
const { enabled, customerIo } = this.config.metrics;
|
||||
if (enabled && customerIo?.token) {
|
||||
const payload = {
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
created_at: Number(user.createdAt) / 1000,
|
||||
};
|
||||
try {
|
||||
await fetch(`https://track.customer.io/api/v1/customers/${user.id}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
Authorization: `Basic ${customerIo.token}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
} catch (e) {
|
||||
this.logger.error('Failed to publish user update event:', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OnEvent('user.deleted')
|
||||
async onUserDeleted(user: EventPayload<'user.deleted'>) {
|
||||
const { enabled, customerIo } = this.config.metrics;
|
||||
if (enabled && customerIo?.token) {
|
||||
try {
|
||||
if (user.emailVerifiedAt) {
|
||||
// suppress email if email is verified
|
||||
await fetch(
|
||||
`https://track.customer.io/api/v1/customers/${user.email}/suppress`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Basic ${customerIo.token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
await fetch(`https://track.customer.io/api/v1/customers/${user.id}`, {
|
||||
method: 'DELETE',
|
||||
headers: { Authorization: `Basic ${customerIo.token}` },
|
||||
});
|
||||
} catch (e) {
|
||||
this.logger.error('Failed to publish user delete event:', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user