Skip to content

Commit

Permalink
Add PlaceEntity fields for current place state information.
Browse files Browse the repository at this point in the history
  • Loading branch information
Misterblue committed Feb 4, 2021
1 parent fa1f04f commit e0148fb
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 12 deletions.
20 changes: 9 additions & 11 deletions src/Entities/PlaceEntity.ts
Expand Up @@ -16,29 +16,27 @@
import Config from '@Base/config';

import { Entity } from '@Entities/Entity';
import { AccountEntity } from '@Entities/AccountEntity';
import { AuthToken } from '@Entities/AuthToken';

import { placeFields } from '@Entities/PlaceFields';

import { getEntityField, setEntityField, getEntityUpdateForField } from '@Route-Tools/GetterSetter';

import { VKeyedCollection } from '@Tools/vTypes';

import { Logger } from '@Tools/Logging';

// NOTE: this class cannot have functions in them as they are just JSON to and from the database
export class PlaceEntity implements Entity {
public id: string; // globally unique place identifier
public name: string; // Human friendly name of the place
public description: string; // Human friendly description of the place
public maturity: string; // tags defining the string content
public maturity: string; // maturity level of the place (see Sets/Maturity.ts)
public tags: string[]; // tags defining the string content
public domainId: string; // domain the place is in
public address: string; // Address within the domain
public thumbnail: string; // thumbnail for place
public images: string[]; // images for the place

// A Place can have a beacon that updates current state and information
// If current information is not supplied, attendence defaults to domain's
public currentAttendence: number // current attendence at the Place
public currentImages: string[] // images at the session
public currentInfo: string // JSON information about the session
public currentLastUpdateTime: Date // time that the last session information was updated
public currentAPIKeyTokenId: string // API key for updating the session information

// admin stuff
public iPAddrOfFirstContact: string; // IP address that registered this place
public whenCreated: Date; // What the variable name says
Expand Down
59 changes: 58 additions & 1 deletion src/Entities/PlaceFields.ts
Expand Up @@ -27,12 +27,13 @@ import { Perm } from '@Route-Tools/Perm';
import { checkAccessToEntity } from '@Route-Tools/Permissions';

import { FieldDefn, ValidateResponse } from '@Route-Tools/EntityFieldDefn';
import { isStringValidator, isSArraySet, isPathValidator, isDateValidator } from '@Route-Tools/Validators';
import { isStringValidator, isSArraySet, isPathValidator, isDateValidator, isNumberValidator } from '@Route-Tools/Validators';
import { simpleGetter, simpleSetter, noSetter, sArraySetter, dateStringGetter } from '@Route-Tools/Validators';

import { IsNullOrEmpty, IsNotNullOrEmpty } from '@Tools/Misc';

import { Logger } from '@Tools/Logging';
import { Tokens } from './Tokens';

// Naming and access for the fields in a PlaceEntity.
// Indexed by request_field_name.
Expand Down Expand Up @@ -175,6 +176,62 @@ export const placeFields: { [key: string]: FieldDefn } = {
setter: sArraySetter,
getter: simpleGetter
},
'current_attendance': {
entity_field: 'currentAttendence',
request_field_name: 'current_attendance',
get_permissions: [ Perm.ALL ],
set_permissions: [ Perm.DOMAINACCESS, Perm.ADMIN ],
validate: isNumberValidator,
setter: simpleSetter,
getter: simpleGetter
},
'current_images': {
entity_field: 'currentImages',
request_field_name: 'current_images',
get_permissions: [ Perm.ALL ],
set_permissions: [ Perm.DOMAINACCESS, Perm.ADMIN ],
validate: isSArraySet,
setter: sArraySetter,
getter: simpleGetter
},
'current_info': {
entity_field: 'currentInfo',
request_field_name: 'current_info',
get_permissions: [ Perm.ALL ],
set_permissions: [ Perm.DOMAINACCESS, Perm.ADMIN ],
validate: isStringValidator,
setter: simpleSetter,
getter: simpleGetter
},
'current_last_update_time': {
entity_field: 'currentLastUpdateTime',
request_field_name: 'current_last_update_time',
get_permissions: [ Perm.DOMAINACCESS, Perm.ADMIN ],
set_permissions: [ Perm.NONE ],
validate: isDateValidator,
setter: simpleSetter,
getter: dateStringGetter
},
'current_api_key': {
entity_field: 'currentAPIKeyTokenId',
request_field_name: 'current_api_key',
get_permissions: [ Perm.DOMAINACCESS, Perm.ADMIN],
set_permissions: [ Perm.NONE ],
validate: isStringValidator,
setter: noSetter,
getter: async (pField: FieldDefn, pEntity: Entity): Promise<any> => {
if (pEntity.hasOwnProperty('currentAPIKeyTokenId')) {
const tokenId = (pEntity as PlaceEntity).currentAPIKeyTokenId;
if (IsNotNullOrEmpty(tokenId)) {
const aToken = await Tokens.getTokenWithTokenId(tokenId);
if (aToken) {
return aToken.token;
};
};
};
return 'unknown';
}
},
// admin stuff
'addr_of_first_contact': {
entity_field: 'iPAddrOfFirstContact',
Expand Down

0 comments on commit e0148fb

Please sign in to comment.