Skip to content

Commit

Permalink
feat: made docs optional
Browse files Browse the repository at this point in the history
/spend 5m
  • Loading branch information
nico-i committed Mar 31, 2024
1 parent 85d1093 commit e500893
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 38 deletions.
6 changes: 0 additions & 6 deletions src/entities/cert/repo/cert-repo.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import type { Cert } from "@/entities/cert";
import type { Locale } from "@/value-objects/locale";

export class InvalidCertDocError extends Error {
constructor() {
super("doc attribute must have a url attribute");
}
}

export interface CertRepo {
getAllCerts(locale: Locale): Promise<Cert[]>;
}
21 changes: 5 additions & 16 deletions src/entities/cert/repo/strapi/strapi-cert-repo.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { Cert } from "@/entities/cert";
import {
InvalidCertDocError,
type CertRepo,
} from "@/entities/cert/repo/cert-repo";
import { type CertRepo } from "@/entities/cert/repo/cert-repo";
import { InvalidLocalizedEntityError } from "@/entities/entity";
import type { StrapiClient } from "@/infrastructure/interfaces/strapi";
import { Doc } from "@/value-objects/doc";
import { Doc } from "@/value-objects";
import { Locale } from "@/value-objects/locale";
import { Markdown } from "@/value-objects/markdown/markdown";

Expand All @@ -28,16 +25,6 @@ export class StrapiCertRepo implements CertRepo {
if (!locale) {
throw new InvalidLocalizedEntityError();
}
let certDoc: Doc | undefined;

if (doc) {
if (!doc.data?.attributes?.url) {
throw new InvalidCertDocError();
}
certDoc = new Doc(new URL(doc.data.attributes.url));
} else {
certDoc = undefined;
}

certs.push(
new Cert(
Expand All @@ -47,7 +34,9 @@ export class StrapiCertRepo implements CertRepo {
issuer,
received,
new Markdown(info),
certDoc,
resCert.attributes.doc?.data?.attributes?.url
? new Doc(new URL(resCert.attributes.doc.data.attributes.url))
: undefined,
url ? new URL(url) : undefined
)
);
Expand Down
6 changes: 0 additions & 6 deletions src/entities/ed/repo/ed-repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,3 @@ import type { Locale } from "@/value-objects/locale";
export interface EdRepo {
getAllEds(locale: Locale): Promise<Ed[]>;
}

export class InvalidEdDocError extends Error {
constructor(e: unknown) {
super(`Invalid Ed Doc: ${e}`);
}
}
14 changes: 4 additions & 10 deletions src/entities/ed/repo/strapi/strapi-ed-repo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Ed } from "@/entities/ed";
import { InvalidEdDocError, type EdRepo } from "@/entities/ed/repo";
import { type EdRepo } from "@/entities/ed/repo";
import { InvalidLocalizedEntityError } from "@/entities/entity";
import type { StrapiClient } from "@/infrastructure/interfaces/strapi";
import { Doc } from "@/value-objects/doc/doc";
Expand All @@ -25,14 +25,6 @@ export class StrapiEdRepo implements EdRepo {
throw new InvalidLocalizedEntityError();
}

let edDoc: Doc | undefined = undefined;
if (doc) {
if (!doc.data?.attributes?.url) {
throw new InvalidEdDocError("url not found in doc data attributes");
}
edDoc = new Doc(new URL(doc.data.attributes.url));
}

eds.push(
new Ed(
resEd.id,
Expand All @@ -42,7 +34,9 @@ export class StrapiEdRepo implements EdRepo {
start,
grade,
url ? new URL(url) : undefined,
edDoc,
resEd.attributes.doc?.data?.attributes?.url
? new Doc(new URL(resEd.attributes.doc.data.attributes.url))
: undefined,
end
)
);
Expand Down

0 comments on commit e500893

Please sign in to comment.