mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) move home server into core
Summary: This moves enough server material into core to run a home server. The data engine is not yet incorporated (though in manual testing it works when ported). Test Plan: existing tests pass Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2552
This commit is contained in:
46
app/gen-server/entity/Resource.ts
Normal file
46
app/gen-server/entity/Resource.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import {BaseEntity, Column} from "typeorm";
|
||||
import {ApiError} from 'app/common/ApiError';
|
||||
import {CommonProperties} from "app/common/UserAPI";
|
||||
|
||||
export class Resource extends BaseEntity {
|
||||
@Column()
|
||||
public name: string;
|
||||
|
||||
@Column({name: 'created_at', default: () => "CURRENT_TIMESTAMP"})
|
||||
public createdAt: Date;
|
||||
|
||||
@Column({name: 'updated_at', default: () => "CURRENT_TIMESTAMP"})
|
||||
public updatedAt: Date;
|
||||
|
||||
// a computed column which, when present, means the entity should be filtered out
|
||||
// of results.
|
||||
@Column({name: 'filtered_out', type: 'boolean', select: false, insert: false})
|
||||
public filteredOut?: boolean;
|
||||
|
||||
public updateFromProperties(props: Partial<CommonProperties>) {
|
||||
if (props.createdAt) { this.createdAt = _propertyToDate(props.createdAt); }
|
||||
if (props.updatedAt) {
|
||||
this.updatedAt = _propertyToDate(props.updatedAt);
|
||||
} else {
|
||||
this.updatedAt = new Date();
|
||||
}
|
||||
if (props.name) { this.name = props.name; }
|
||||
}
|
||||
|
||||
protected checkProperties(props: any, keys: string[]): props is Partial<CommonProperties> {
|
||||
for (const key of Object.keys(props)) {
|
||||
if (!keys.includes(key)) {
|
||||
throw new ApiError(`unrecognized property ${key}`, 400);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure iso-string-or-date value is converted to a date.
|
||||
function _propertyToDate(d: string|Date): Date {
|
||||
if (typeof(d) === 'string') {
|
||||
return new Date(d);
|
||||
}
|
||||
return d;
|
||||
}
|
||||
Reference in New Issue
Block a user