From ab86081dd909265cfd448deb0d28a293d66290e0 Mon Sep 17 00:00:00 2001 From: Mal <=> Date: Tue, 8 Sep 2020 14:21:04 +0200 Subject: [PATCH] Fingerprint creation implemented. --- js/api/FingerprintPostApiRequest.ts | 29 +++++++++++++++++++++++++++++ js/event/FingerprintCreatedEvent.ts | 18 ++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 js/api/FingerprintPostApiRequest.ts create mode 100644 js/event/FingerprintCreatedEvent.ts diff --git a/js/api/FingerprintPostApiRequest.ts b/js/api/FingerprintPostApiRequest.ts new file mode 100644 index 0000000..c966534 --- /dev/null +++ b/js/api/FingerprintPostApiRequest.ts @@ -0,0 +1,29 @@ +import ApiRequest from "./ApiRequest.js"; +import RequestMethod from "./RequestMethod.js"; +import Fingerprint from "../types/Fingerprint.js"; +import FingerprintCreatedEvent from "../event/FingerprintCreatedEvent.js"; + +export default class FingerprintPostApiRequest extends ApiRequest +{ + private fingerprint: string; + private userId: number; + + public constructor(fingerprint: string, userId: number) { + super('fingerprint', RequestMethod.POST); + + this.fingerprint = fingerprint; + this.userId = userId; + + this.addParameter('fingerprint', this.fingerprint); + this.addParameter('userId', this.userId); + + this.setOnSuccess( + (response: string) => { + let json = JSON.parse(response); + let fingerprint = new Fingerprint(json.userId, this.fingerprint, this.userId); + + window.dispatchEvent(new FingerprintCreatedEvent(fingerprint)); + } + ); + } +} \ No newline at end of file diff --git a/js/event/FingerprintCreatedEvent.ts b/js/event/FingerprintCreatedEvent.ts new file mode 100644 index 0000000..3b4438d --- /dev/null +++ b/js/event/FingerprintCreatedEvent.ts @@ -0,0 +1,18 @@ +import RingfingerEvent from "./RingfingerEvent.js"; +import Fingerprint from "../types/Fingerprint.js"; + +export default class FingerprintCreatedEvent extends RingfingerEvent +{ + private fingerprint: Fingerprint; + + public constructor(fingerprint: Fingerprint) { + super(FingerprintCreatedEvent.name); + + this.fingerprint = fingerprint; + } + + public getFingerprint(): Fingerprint + { + return this.fingerprint; + } +} \ No newline at end of file