Skip to content

Instantly share code, notes, and snippets.

@MaxLarue
Last active July 9, 2022 15:52
Show Gist options
  • Save MaxLarue/fe54baa5491cdb7e7d5f5a34322b1a2a to your computer and use it in GitHub Desktop.
Save MaxLarue/fe54baa5491cdb7e7d5f5a34322b1a2a to your computer and use it in GitHub Desktop.
appointment with events
@Injectable()
export class AppointmentService {
constructor(@InjectRepository(Appointment) private readonly repository: Repository<Appointment>,
@Inject(AppointmentPermissionService) private readonly appointmentPermissionService: AppointmentPermissionService,
@Inject(EVENT_PUBLISHER_TOKEN) private readonly eventPublisher: EventPublisher) {}
async create(values: DeepPartial<Appointment>, currentUser: User) {
await this.appointmentPermissionService.verifyCanCreate(currentUser, values)
const appointment = await this.repository.save(values)
await this.eventPublisher.publish(makeAppointmentCreatedEvent(appointment.id))
return appointment
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment