Skip to content

Commit 1362873

Browse files
committed
Added allowRealPubicId to ving schema props.
* Fixed: filter on id #203 * Fixed: How to do a search for hardware ticket by ticket number? #29
1 parent c5beb9d commit 1362873

File tree

6 files changed

+54
-4
lines changed

6 files changed

+54
-4
lines changed

ving/docs/change-log.md

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ Also don't forget to update the imports in your schema files.
3131
* Set filterQualifier to true for the baseSchemaId.
3232
* Added better error handling for int2str parseId().
3333
* Added stringToNumber option to int2str parseId().
34+
* Added allowRealPubicId to ving schema props.
35+
* Fixed: filter on id #203
36+
* Fixed: How to do a search for hardware ticket by ticket number? #29
3437

3538
## December 2024
3639

ving/docs/subsystems/ui.md

+10
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,16 @@ await users.search();
467467
onBeforeRouteLeave(() => users.dispose());
468468
```
469469
470+
#### Filtering
471+
472+
You can filter the list of records by passing in values to the query object. For example, to filter by an exact value:
473+
474+
```js
475+
users.query.id = 'xxx';
476+
```
477+
For more on filtering see the [rest api](rest#filters) documentation.
478+
479+
470480
### useVingRecord()
471481
A client for interacting with [server-side ving records](ving-record#record-api) through the [Rest API](rest).
472482

ving/docs/subsystems/ving-schema.md

+7
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,13 @@ An optional boolean that if true will allow searching via the [rest api](rest) f
385385
An optional boolean that if true will allow searching via the [rest api](rest) for range matching against this field. This is an alternative to overriding the `describeListFilter()` method in [VingRecord](ving-record). Only use on `int` and `date` type props.
386386

387387

388+
##### allowRealPubicId
389+
390+
An optional boolean that if true will do 2 things if added to an `id` prop `type`:
391+
392+
* Allows searching via the [rest api](rest) for exact match filtering against this id using its integer value in addiont to the encrypted string assuming `filterQualifier` is true.
393+
* Adds the real id to the `meta.realId` object in the [rest api](rest) response.
394+
388395
##### autoUpdate
389396

390397
The `autoUpdate` field is an optional boolean that is only used on a prop with type `date`. If `true` the date will automatically get set every time `update()` is called on the record. This is generally never needed by anything other than the built in `dateUpdated` record that every record already has.

ving/record/VingRecord.mjs

+11-2
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ export class VingRecord {
203203
}
204204

205205
for (const field of schema.props) {
206+
207+
// meta
208+
if (isObject(out.meta)
209+
&& include.meta
210+
) {
211+
if (field.allowRealPubicId) {
212+
if (!isObject(out.meta.realId)) out.meta.realId = {};
213+
out.meta.realId[field.name] = this.#props[field.name];
214+
}
215+
}
216+
206217
if (field.name == 'id') // already done
207218
continue;
208219

@@ -214,8 +225,6 @@ export class VingRecord {
214225
|| (currentUser?.isaRole(roles));
215226
if (!visible) continue;
216227

217-
const fieldName = field.name.toString();
218-
219228
// props
220229
if (field.type == 'id')
221230
out.props[field.name] = stringifyId(this.#props[field.name], field.relation?.kind || schema.kind);

ving/schema/validator.mjs

+22-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export const validateProps = (schema) => {
7272
validatePropFilterQuery(prop, schema);
7373
validatePropFilterQualifier(prop, schema);
7474
validatePropAutoUpdate(prop, schema);
75+
validatePropAllowRealPubicId(prop, schema);
7576
}
7677
}
7778

@@ -508,7 +509,7 @@ export const validatePropFilterQualifier = (prop, schema) => {
508509
return;
509510
if (!isBoolean(prop.filterQualifier))
510511
throw ving.ouch(442, `${formatPropPath(prop, schema)}.filterQualifier must be a boolean.`);
511-
if (prop.type == 'id' && prop.relation?.type != 'parent')
512+
if (prop.type == 'id' && prop.relation && prop.relation?.type != 'parent')
512513
throw ving.ouch(442, `${formatPropPath(prop, schema)}.filterQualifier can only exist on type id if the relation.type is parent.`);
513514
}
514515

@@ -532,6 +533,26 @@ export const validatePropFilterRange = (prop, schema) => {
532533
throw ving.ouch(442, `${formatPropPath(prop, schema)}.filterRange must be a boolean.`);
533534
}
534535

536+
/**
537+
* Validates the allowRealPubicId field of a prop.
538+
* @param {object} prop The prop schema to check against.
539+
* @param {VingSchema} schema The schema to check against.
540+
* @throws 442 if some attribute is outside of the normal definition
541+
* @example
542+
* validatePropAllowRealPubicId(prop, schema)
543+
*/
544+
export const validatePropAllowRealPubicId = (prop, schema) => {
545+
if (!['id'].includes(prop.type)) {
546+
if ('allowRealPubicId' in prop)
547+
throw ving.ouch(442, `${formatPropPath(prop, schema)}.allowRealPubicId should not exist.`);
548+
return;
549+
}
550+
if (!('allowRealPubicId' in prop)) // not required
551+
return;
552+
if (!isBoolean(prop.allowRealPubicId))
553+
throw ving.ouch(442, `${formatPropPath(prop, schema)}.allowRealPubicId must be a boolean.`);
554+
}
555+
535556
/**
536557
* Validates the required field of a prop.
537558
* @param {object} prop The prop schema to check against.

ving/utils/rest.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const fixColumnData = (column, data) => {
2525
return data == 'true' ? true : false;
2626
}
2727
if (column.vingSchemaProp.type == 'id') {
28-
return parseId(data);
28+
return parseId(data, { stringToNumber: column.vingSchemaProp.allowRealPubicId ? true : false });
2929
}
3030
if (column.vingSchemaProp.type == 'int') {
3131
return Number(data);

0 commit comments

Comments
 (0)