Skip to content

Commit

Permalink
advance types and services
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasdodersidedrawer committed Nov 24, 2021
1 parent a35d072 commit c118f43
Show file tree
Hide file tree
Showing 29 changed files with 375 additions and 54 deletions.
49 changes: 33 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"typings": "dist/index.d.ts",
"files": [
"dist"

],
"engines": {
"node": ">=12"
Expand Down Expand Up @@ -66,6 +65,8 @@
"dependencies": {
"@auth0/auth0-spa-js": "^1.18.0",
"axios": "^0.21.1",
"form-data": "^4.0.0",
"fs": "0.0.1-security",
"openid-client": "^4.7.4",
"rxjs": "^6.6.7"
}
Expand Down
4 changes: 4 additions & 0 deletions src/services/base-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export default class BaseService {
return this.instance.post<T, AxiosResponse<T>>(url, data, config);
}

protected put = async <T = any>(url: string, data?: any, config?: AxiosRequestConfig): Promise<AxiosResponse<T>> => {
await this.setToken();
return this.instance.put<T, AxiosResponse<T>>(url, data, config);
}

private setToken = async () => {
if (!auth)
Expand Down
27 changes: 17 additions & 10 deletions src/services/network-service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { AxiosResponse } from 'axios';
import config from '../config.json';
import BaseService from './base-service';
import { SideDrawer } from '../types/sidedrawer';
import { SideDrawerMain } from '../types';


export interface INetworkService {

getTimeline(sidedrawer_id: string, type: string): Promise<AxiosResponse<any>>;
getShared(): Promise<AxiosResponse<any>>;
getOwned(): Promise<AxiosResponse<SideDrawer[]>>;
getTimeline(sidedrawer_id: string, type: string, locale: string, page: number): Promise<AxiosResponse<any>>;
getShared(): Promise<AxiosResponse<SideDrawerMain[]>>;
getOwned(): Promise<AxiosResponse<SideDrawerMain[]>>;
remove(sidedrawer_id: string): Promise<AxiosResponse<any>>;

}

Expand All @@ -18,22 +19,28 @@ export default class NetworkService extends BaseService implements INetworkServi

}

getTimeline = async (sidedrawer_id: string, type: string): Promise<AxiosResponse<any>> => {
getTimeline = async (sidedrawer_id: string, type: string, locale: string, page: number): Promise<AxiosResponse<any>> => {

return this.get(`sidedrawer/sidedrawer-id/${sidedrawer_id}/log?locale=en-CA&page=1&entityType=${type}`);
return this.get(`sidedrawer/sidedrawer-id/${sidedrawer_id}/log?locale==${locale}&page=${page}&entityType=${type}`);

};

getShared = async (): Promise<AxiosResponse<any>> => {
getShared = async (): Promise<AxiosResponse<SideDrawerMain[]>> => {

return this.get(`sidedrawer/shared`);
return this.get<SideDrawerMain[]>(`sidedrawer/shared`);
};

getOwned = async (): Promise<AxiosResponse<SideDrawer[]>> => {
getOwned = async (): Promise<AxiosResponse<SideDrawerMain[]>> => {

return this.get<SideDrawer[]>(`sidedrawer/owned`);
return this.get<SideDrawerMain[]>(`sidedrawer/owned`);
};

remove = async (sidedrawer_id: string): Promise<AxiosResponse<any>> => {

return this.delete(`sidedrawer/sidedrawer-id/${sidedrawer_id}`);
};


}


13 changes: 5 additions & 8 deletions src/services/record-service.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
import config from '../config.json';
import BaseService from './base-service';
import { AxiosResponse } from 'axios';
import { Record } from '../types';


export interface IRecordService {

getBySidedrawer(sidedrawer_id: string): Promise<AxiosResponse<any>>;
getUserSetting(user_id: string): Promise<AxiosResponse<any>>;
getBySidedrawer(sidedrawer_id: string): Promise<AxiosResponse<Record[]>>;


}
export default class RecordService extends BaseService implements IRecordService {
constructor() {
super(config.apiRecord);
}

getBySidedrawer = async (sidedrawer_id: string): Promise<AxiosResponse<any>> => {
return this.get(`sidedrawer/sidedrawer-id/${sidedrawer_id}/records`);
getBySidedrawer = async (sidedrawer_id: string): Promise<AxiosResponse<Record[]>> => {
return this.get<Record[]>(`sidedrawer/sidedrawer-id/${sidedrawer_id}/records`);

};

getUserSetting = async (user_id: string): Promise<AxiosResponse<any>> => {

return this.get(`/accounts/account-id/${user_id}/settings`);

};

}

Expand Down
21 changes: 20 additions & 1 deletion src/services/recordFile-service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import config from '../config.json';
import BaseService from './base-service';
import { AxiosResponse } from 'axios';
import { RecordFile } from '../types/recordFile';
import { RecordFile } from '../types';
import FormData from 'form-data';
import fs from 'fs';


export interface IRecordFileService {

getByRecord(sidedrawer_id: string, record_id: string): Promise<AxiosResponse<RecordFile[]>>;
remove(sidedrawer_id: string, record_id: string, fileName: string): Promise<AxiosResponse<any>>;
getStreamByUrl(url: string): Promise<AxiosResponse<any>>;
postLocalFile(sidedrawer_id: string, record_id: string, urlFile: string, recordFile: RecordFile): Promise<AxiosResponse<any>>;

}
export default class RecordFileService extends BaseService implements IRecordFileService {
Expand All @@ -32,6 +35,22 @@ export default class RecordFileService extends BaseService implements IRecordFil

};

postLocalFile = async (sidedrawer_id: string, record_id: string, urlFile: string, recordFile: RecordFile): Promise<AxiosResponse<any>> => {

const formData = new FormData();
formData.append('file', fs.createReadStream(urlFile));

const params = new URLSearchParams({
fileName: recordFile.fileName!, correlationId: recordFile.correlationId!, uploadTitle: recordFile.uploadTitle!, fileType: recordFile.fileType!
}).toString();
const url = `sidedrawer/sidedrawer-id/${sidedrawer_id}/records/record-id/${record_id}/record-files?${params}`;

return this.post(url, formData);

};




}

Expand Down
13 changes: 7 additions & 6 deletions src/services/sidedrawer-service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import config from '../config.json';
import BaseService from './base-service';
import { AxiosResponse } from 'axios';
import { SideDrawer } from '../types';


export interface ISidedrawerSevice {

getHome(sidedrawer_id: string): Promise<AxiosResponse<any>>;
getById(user_id: string): Promise<AxiosResponse<any>>;
getHome(sidedrawer_id: string, locale: string): Promise<AxiosResponse<SideDrawer>>;
getById(user_id: string): Promise<AxiosResponse<SideDrawer>>;

}

Expand All @@ -15,13 +16,13 @@ export default class SidedrawerSevice extends BaseService implements ISidedrawer
super(config.apiRecord);
}

getHome = async (sidedrawer_id: string) => {
return this.get(`sidedrawer/sidedrawer-id/${sidedrawer_id}/home?locale=en-CA`);
getHome = async (sidedrawer_id: string, locale: string): Promise<AxiosResponse<SideDrawer>> => {
return this.get<SideDrawer>(`sidedrawer/sidedrawer-id/${sidedrawer_id}/home?locale=${locale}`);

};

getById = async (sidedrawer_id: string) => {
return this.get(`sidedrawer/sidedrawer-id/${sidedrawer_id}`);
getById = async (sidedrawer_id: string): Promise<AxiosResponse<SideDrawer>> => {
return this.get<SideDrawer>(`sidedrawer/sidedrawer-id/${sidedrawer_id}`);

};

Expand Down
25 changes: 25 additions & 0 deletions src/types/account.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Settings } from './settings'
import { PrimaryResidence } from './primaryResidence'
import { Email } from './Email'
import { Agreement } from './agreement'
import { Phone } from './phone'


export interface Account {
id?: string,
username?: string,
firstName?: string,
lastName?: string,
profilePhoto?: string,
dateOfBirth?: string,
maritalStatus?: string,
primaryResidence?: PrimaryResidence,
gender?: string,
emails?: Email[],
phones?: Phone[],
settings?: Settings,
agreements?: Agreement[],
openId?: string,
customerId?: string

}
7 changes: 7 additions & 0 deletions src/types/agreement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface Agreement {
locale: string,
type: string,
version: number,
consent: boolean

}
12 changes: 12 additions & 0 deletions src/types/contributor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { DisplayValue } from './displayValue'

export interface Contributor {

openId?: string,
firstName?: string,
lastName?: string,
email?: string,
phoneNumber?: string,
teamId?: string,

}
Loading

0 comments on commit c118f43

Please sign in to comment.