Skip to content

Commit

Permalink
✨ deal with date objects
Browse files Browse the repository at this point in the history
  • Loading branch information
bunop committed Jun 20, 2024
1 parent 94215f5 commit 4daf9e4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/app/shared/shared.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ export interface ObjectID {
$oid: string;
}

export class ObjectDate {
$date: Date;

constructor(value: string | Date) {
if (value instanceof Date) {
this.$date = value;
} else {
this.$date = new Date(value);
}
}
}

// https://dev.to/ankittanna/how-to-create-a-type-for-complex-json-object-in-typescript-d81
export type JSONValue =
| string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ <h2>id: {{ variant._id.$oid }}</h2>
<mat-card-content>
<mat-list-item role="listitem">Chrom: {{ location.chrom }}</mat-list-item>
<mat-list-item role="listitem">Position: {{ location.position }}</mat-list-item>
<mat-list-item role="listitem"*ngIf="location.date" >Date: {{ location.date.$date | date:'longDate':'en-US' }}</mat-list-item>
<mat-list-item role="listitem" *ngIf="location.illumina">Illumina: {{ location.illumina }}</mat-list-item>
<mat-list-item role="listitem">Illumina TOP: {{ location.illumina_top }}</mat-list-item>
<mat-list-item role="listitem" *ngIf="location.illumina_forward">Illumina Forward: {{ location.illumina_forward }}</mat-list-item>
Expand Down
4 changes: 2 additions & 2 deletions src/app/variants/variants.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { JSONObject, ObjectID } from "../shared/shared.model";
import { JSONObject, ObjectID, ObjectDate } from "../shared/shared.model";

export interface Location {
ss_id?: string;
Expand All @@ -14,7 +14,7 @@ export interface Location {
affymetrix_ab?: string;
strand?: string;
imported_from: string;
date?: JSONObject;
date?: ObjectDate;
}

export interface Probeset {
Expand Down
13 changes: 12 additions & 1 deletion src/app/variants/variants.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { map } from 'rxjs/operators';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { SortDirection } from '@angular/material/sort';
import { environment } from 'src/environments/environment';

import { SupportedChip, SupportedChipsAPI, Variant, VariantsAPI, VariantsSearch } from './variants.model';
import { Observable, Subject, forkJoin } from 'rxjs';
import { ObjectDate } from '../shared/shared.model';

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -69,7 +71,16 @@ export class VariantsService {

getVariant(_id: string, species: string) {
const url = environment.backend_url + '/variants/' + species + "/" + _id;
return this.http.get<Variant>(url);
return this.http.get<Variant>(url).pipe(
map((variant: Variant) => {
variant.locations.forEach((location) => {
if (location.date) {
location.date = new ObjectDate(location.date.$date);
}
});
return variant;
})
);
}

getSupportedChips(species: string,): void {
Expand Down

0 comments on commit 4daf9e4

Please sign in to comment.