Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add config for models to transform ionic date format (#33)
- Loading branch information
1 parent
d9efab3
commit afc5fd7
Showing
5 changed files
with
43 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { plainToClass } from 'class-transformer'; | ||
import { IRestProviderOptions, PaginationMeta, ProviderActionEnum } from 'ngx-repository'; | ||
import { CustomUser } from '../models/custom-user'; | ||
|
||
export const IONIC_DEFAULT_USERS_CONFIG: IRestProviderOptions<CustomUser> = { | ||
name: 'user', | ||
pluralName: 'users', | ||
autoload: true, | ||
paginationMeta: { | ||
perPage: 5 | ||
}, | ||
actionOptions: { | ||
responseData: (data: any, action: ProviderActionEnum) => { | ||
if (action === ProviderActionEnum.Delete) { | ||
return true; | ||
} else { | ||
if (action === ProviderActionEnum.LoadAll) { | ||
return plainToClass(CustomUser, data && data.body && data.body.users); | ||
} else { | ||
return plainToClass(CustomUser, data && data.body && data.body.user); | ||
} | ||
} | ||
}, | ||
responsePaginationMeta: (data: any, action: ProviderActionEnum): PaginationMeta => { | ||
return { totalResults: data && data.body && data.body.meta && data.body.meta.totalResults, perPage: undefined }; | ||
} | ||
}, | ||
restOptions: { | ||
limitQueryParam: 'per_page', | ||
pageQueryParam: 'cur_page', | ||
searchTextQueryParam: 'q' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { User, transformDateToString } from '@rucken/core'; | ||
import { transformDateToString, transformStringToDate, User } from '@rucken/core'; | ||
import { Transform } from 'class-transformer'; | ||
|
||
export class CustomUser extends User { | ||
@Transform(transformDateToString, { toClassOnly: true }) | ||
@Transform(transformDateToString, { toPlainOnly: true }) | ||
dateOfBirth: Date = undefined; | ||
@Transform(transformStringToDate, { toPlainOnly: true }) | ||
dateOfBirth: Date | string = undefined; | ||
} |