class-validator#isEmpty TypeScript Examples
The following examples show how to use
class-validator#isEmpty.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utils.ts From IBM-HyperProtectMBaaS with BSD 3-Clause "New" or "Revised" License | 7 votes |
/**
* Adds new (unknown) clocks to local db. It will set local clock to the max of twc clocks
*
* @param processes clocks (typically from a knowledge vector )
*/
export async function mergeKnowledgeVectors(processes: Process[]) {
let clockRepo = getMongoRepository(Process);
for (const process of processes) {
const processExists = await clockRepo.findOne({ id: process.id });
if (isEmpty(processExists)) {
assert(isNotEmpty(process.id));
await clockRepo.save(process);
} else {
assert(process.id === processExists.id);
const maxClock = Math.max(processExists.clock, process.clock);
if (maxClock === process.clock) await clockRepo.updateOne({ id: process.id }, { $set: { clock: maxClock } });
}
}
}
Example #2
Source File: EnableEntity.ts From IBM-HyperProtectMBaaS with BSD 3-Clause "New" or "Revised" License | 6 votes |
export async function processEntity(...entityParams) {
if (entityParams) {
entity = entityParams[0];
repository = entityParams[1];
} else {
console.log("Incorrect number of params sent from RevisionRecord to EnableEntity");
}
try {
const entityExists = await repository.findOne({ uuid: entity.object.uuid });
// if entity exists, don't overwrite
if (isEmpty(entityExists)) {
const task = repository.create(entity.object);
task.kv = await getLatestKnowledgeVector();
console.log(util.inspect(task, false, null, true /* enable colors */));
await repository.save(task);
//await createOrIncrementClock();
}
} catch (e) {
//res.status(409).send("Entity exists");
return;
}
}
Example #3
Source File: RevisionRecordController.ts From IBM-HyperProtectMBaaS with BSD 3-Clause "New" or "Revised" License | 6 votes |
/**
* TODO Implement id based lookup
* @param req
* @param res
*/
static getOneById = async (req: Request, res: Response) => {
const revisionRecordRepository = getRepository(OCKRevisionRecord);
const revisionRecords = await revisionRecordRepository.find();
//console.log(util.inspect(revisionRecords, false, null, true /* enable colors */));
res.send(isEmpty(revisionRecords) ? {} : revisionRecords);
};
Example #4
Source File: files.entity.ts From NestJs-youtube with MIT License | 5 votes |
@Column({ length: 50 })
@IsString({ always: true })
@IsEmpty({ always: true, message: 'hey...' })
// tslint:disable-next-line: variable-name
original_name: string;
Example #5
Source File: files.entity.ts From NestJs-youtube with MIT License | 5 votes |
@Column({ length: 50 })
@IsString({ always: true })
@IsEmpty({ always: true, message: 'hey...' })
// tslint:disable-next-line: variable-name
current_name: string;
Example #6
Source File: files.entity.ts From NestJs-youtube with MIT License | 5 votes |
@Column({ length: 50 })
@IsString({ always: true })
@IsEmpty({ always: true, message: 'hey...' })
extention: string;
Example #7
Source File: files.entity.ts From NestJs-youtube with MIT License | 5 votes |
@Column({ type: 'int' })
@IsNumber()
@IsEmpty({ always: true, message: 'hey...' })
size: number;
Example #8
Source File: posts.entity.ts From NestJs-youtube with MIT License | 5 votes |
@Column({ default: 0, type: 'int' })
@IsEmpty({ always: true, message: 'hey...' })
@IsNumber({ allowNaN: false, allowInfinity: false })
// tslint:disable-next-line: variable-name
comments_num: number;
Example #9
Source File: user.entity.ts From NestJs-youtube with MIT License | 5 votes |
@Column({ type: 'enum', enum: Roles, default: Roles.user })
@IsEmpty({ always: true, message: 'hey...' })
role: Roles;
Example #10
Source File: RevisionRecordController.ts From IBM-HyperProtectMBaaS with BSD 3-Clause "New" or "Revised" License | 4 votes |
static listAll = async (req: Request, res: Response) => {
console.log(util.inspect(req.query.knowledgeVector, false, null, true /* enable colors */));
if (isEmpty(req.query.knowledgeVector)) {
res
.status(400)
.send(
'Must send an array of knowledge vectors as query param. An empty knowledge vector would be { processes: [{ id : "validUUIDv4" , clock : 0 } ]}'
);
return;
}
// Thorough JSON validation using JSON Schema, TypedJSON and class-validator
const ajv = new Ajv();
const valid = ajv.validate(kvSchema, req.query.knowledgeVector);
if (!valid) {
console.log(ajv.errors);
res.status(400).send(ajv.errors);
return;
}
let incomingKV: KnowledgeVector;
try {
incomingKV = new TypedJSON(KnowledgeVector).parse(req.query.knowledgeVector);
} catch (error) {
res.status(400).send("JSON schema error");
return;
}
console.log(util.inspect(incomingKV, false, null, true /* enable colors */));
const errors = await validate(incomingKV);
if (errors.length > 0) {
res.status(400).send(errors);
return;
}
//console.log(util.inspect(incomingKV, false, null, true /* enable colors */));
let returnRevRecord = new OCKRevisionRecord();
returnRevRecord.entities = [];
// Case 1 : iOS device is syncing for the first time, it has no knowledge of the servers clock
if (isEmpty(incomingKV.processes.find((process) => process.id === uuid))) {
// store incoming clock locally
let clockRepo = getMongoRepository(Process);
for (const process of incomingKV.processes) {
assert(isUUID(process.id));
const processExists = await clockRepo.findOne({ id: process.id });
if (isEmpty(processExists)) {
assert(isNotEmpty(process.id));
await clockRepo.save(process);
}
}
// send all outcomes and tasks
const taskRepository = getMongoRepository(OCKTask);
const tasks = await taskRepository.find({});
const outcomeRepository = getMongoRepository(OCKOutcome);
const outcomes = await outcomeRepository.find({});
tasks.map((entity) => {
delete entity.kv;
returnRevRecord.entities.push({ type: "task", object: entity });
});
outcomes.map((entity) => {
delete entity.kv;
returnRevRecord.entities.push({ type: "outcome", object: entity });
});
// set kv for revisionRecord
returnRevRecord.knowledgeVector = await getLatestKnowledgeVector();
//console.log(util.inspect(returnRevRecord, false, null, true /* enable colors */));
res.status(201).send(returnRevRecord);
return;
}
// Case 2 : It has synced before but its clock might be older than local, send entities newer than clock
const clock = incomingKV.processes.find((process) => process.id === uuid).clock;
assert(!isEmpty(clock), "clock cannot be undefined at this point");
const taskRepository = getMongoRepository(OCKTask);
const tasks = await taskRepository.find({
$and: [{ "kv.processes.clock": { $gt: clock } }, { "kv.processes.id": { $eq: uuid } }],
});
const outcomeRepository = getMongoRepository(OCKOutcome);
const outcomes = await outcomeRepository.find({
$and: [{ "kv.processes.clock": { $gt: clock } }, { "kv.processes.id": { $eq: uuid } }],
});
tasks.map((entity) => {
delete entity.kv;
returnRevRecord.entities.push({ type: "task", object: entity });
});
outcomes.map((entity) => {
delete entity.kv;
returnRevRecord.entities.push({ type: "outcome", object: entity });
});
// set kv for revisionRecord
returnRevRecord.knowledgeVector = await getLatestKnowledgeVector();
//console.log(util.inspect(returnRevRecord, false, null, true /* enable colors */));
res.status(201).send(returnRevRecord);
};