feat: initial mini simple event sourcing for pending application updates
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import EventStore from "../domain/EventStore";
|
||||
import { ApplicationUpdateStarted } from "../domain/events/ApplicationUpdateStarted";
|
||||
|
||||
type TODO_TypeDefinition = any;
|
||||
|
||||
class Application {
|
||||
@@ -52,12 +55,18 @@ class Application {
|
||||
class Caprover {
|
||||
private authToken: string = "";
|
||||
private readonly apiUrl: string;
|
||||
private readonly eventStore: EventStore;
|
||||
|
||||
constructor(readonly domain?: string, private readonly password?: string) {
|
||||
constructor(
|
||||
eventStore: EventStore,
|
||||
readonly domain?: string,
|
||||
private readonly password?: string
|
||||
) {
|
||||
if (!domain || !password) {
|
||||
throw new Error("Missing domain or password");
|
||||
}
|
||||
this.apiUrl = `https://${domain}/api/v2`;
|
||||
this.eventStore = eventStore;
|
||||
}
|
||||
|
||||
async getApps(): Promise<Application[]> {
|
||||
@@ -70,6 +79,16 @@ class Caprover {
|
||||
);
|
||||
}
|
||||
|
||||
async updateApplication(appName: string, version: string) {
|
||||
console.log("TODO: Implement remote call", appName, version); // TODO
|
||||
this.eventStore.append(
|
||||
new ApplicationUpdateStarted(
|
||||
{ id: appName, newVersion: version },
|
||||
new Date()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private async authenticate() {
|
||||
if (this.authToken) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user