This repository has been archived by the owner on Dec 23, 2021. It is now read-only.
forked from jaystack/odata-v4-server
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
153 additions
and
190 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,55 @@ | ||
import { ColumnOptions, Column, PrimaryColumn, EntityOptions, Entity } from 'typeorm'; | ||
import { Edm } from '..'; | ||
import { NotImplementedError } from '../error'; | ||
|
||
|
||
/** | ||
* ODataModel | ||
* | ||
* decorator wrapper of the typeorm `Entity` decorator | ||
* | ||
* @param options | ||
*/ | ||
export function ODataModel(options: EntityOptions = {}) { | ||
return function(target) { | ||
Entity(options)(target); | ||
}; | ||
} | ||
|
||
/** | ||
* ODataColumn | ||
* | ||
* combine `Edm` decorator & typeorm decorator | ||
* | ||
* @param options | ||
*/ | ||
export function ODataColumn(options: ColumnOptions = {}) { | ||
return function(object: any, propertyName: string) { | ||
const { primary } = options; | ||
|
||
Column(options)(object, propertyName); | ||
|
||
if (primary) { | ||
Edm.Key(object, propertyName); | ||
} | ||
|
||
const reflectType = Reflect.getMetadata('design:type', object, propertyName); | ||
|
||
switch (reflectType) { | ||
case String: | ||
Edm.String(object, propertyName); | ||
break; | ||
case Number: | ||
Edm.Int32(object, propertyName); | ||
break; | ||
case Boolean: | ||
Edm.Boolean(object, propertyName); | ||
break; | ||
case Date: | ||
Edm.DateTimeOffset(object, propertyName); | ||
break; | ||
default: | ||
throw new NotImplementedError(`Not support the type of field '${propertyName}'.`); | ||
} | ||
}; | ||
} |
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