Тесты работают, TS билдится

This commit is contained in:
Nikita Dezzpil Orlov committed 2021-09-29 17:11:49 +03:00
1 parent e08d9757bb
commit 9f3a64d76f
36 files changed
+17901

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
import rfdc from 'rfdc'
interface ValuesObject {
[key: string]: any
}
export abstract class Data {
static assign(vo: Data, values: ValuesObject): Data {
for (let key of Object.getOwnPropertyNames(values)) {
vo[key] = values[key]
}
return vo
}
[key: string]: any
set(key: string, value: any) {
this[key] = value
}
fromObject(obj: ValuesObject): void {
for (let key of Object.getOwnPropertyNames(obj)) {
if (key === '_id') continue
this[key] = obj[key]
}
}
toObject(exclude: string[] = []): object {
const obj = {} as ValuesObject
for (let key of Object.getOwnPropertyNames(this)) {
if (key.startsWith('__')) {
continue
}
if (exclude.includes(key)) continue
const type = typeof this[key]
if (type === 'object') {
obj[key] = rfdc()(this[key])
} else if (['function', 'undefined'].indexOf(type) >= 0) {
// ...
} else {
obj[key] = this[key]
}
}
return obj
}
abstract uniqKey(): string
}