Added search in registration tokens
MODIFY
src/assets/server/rest/v1/schemas/registration-token/registration-tokens-get.json
src/assets/server/rest/v1/schemas/registration-token/registration-tokens-get.json
"description": "",
"type": "object",
"properties": {
+ "Search": {
+ "$ref": "common#/definitions/search"
+ },
"SiteAreaID": {
"$ref": "registration-token#/definitions/siteAreaID"
},

MODIFY
src/server/rest/v1/service/RegistrationTokenService.ts
src/server/rest/v1/service/RegistrationTokenService.ts
@@ -227,6 +227,7 @@ export default class RegistrationTokenService {
// Get the tokens
const registrationTokens = await RegistrationTokenStorage.getRegistrationTokens(req.tenant,
{
+ search: filteredRequest.Search,
siteAreaID: filteredRequest.SiteAreaID,
siteIDs: Authorizations.getAuthorizedSiteAdminIDs(req.user, null),
},

MODIFY
src/storage/mongodb/RegistrationTokenStorage.ts
src/storage/mongodb/RegistrationTokenStorage.ts
@@ -37,7 +37,7 @@ export default class RegistrationTokenStorage {
}
static async getRegistrationTokens(tenant: Tenant,
- params: { tokenIDs?: string[]; siteIDs?: string[]; siteAreaID?: string } = {}, dbParams: DbParams, projectFields?: string[]):
+ params: { search?: string; tokenIDs?: string[]; siteIDs?: string[]; siteAreaID?: string } = {}, dbParams: DbParams, projectFields?: string[]):
Promise<DataResult<RegistrationToken>> {
const startTime = Logging.traceDatabaseRequestStart();
DatabaseUtils.checkTenantObject(tenant);
@@ -56,6 +56,17 @@ export default class RegistrationTokenStorage {
});
// Set the filters
const filters: FilterParams = {};
+ // Search
+ if (params.search) {
+ filters.$or = [
+ { 'description': { $regex: params.search, $options: 'i' } },
+ ];
+ if (DatabaseUtils.isObjectID(params.search)) {
+ filters.$or.push(
+ { '_id': DatabaseUtils.convertToObjectID(params.search) },
+ );
+ }
+ }
// Build filter
if (params.siteAreaID) {
filters.siteAreaID = DatabaseUtils.convertToObjectID(params.siteAreaID);

MODIFY
src/types/requests/HttpRegistrationToken.ts
src/types/requests/HttpRegistrationToken.ts
@@ -3,6 +3,7 @@ import HttpDatabaseRequest from './HttpDatabaseRequest';
import RegistrationToken from '../RegistrationToken';
export interface HttpRegistrationTokensRequest extends HttpDatabaseRequest {
+ Search: string;
SiteAreaID: string;
}

Added search in registration tokens