This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.getCollection('search_params') | |
.find({ propertyCode: /R.+/ }) | |
.sort({ propertyCode: -1 }) | |
db.getCollection('search_params').aggregate([ | |
{ | |
$match: { | |
propertyCode: /^R.+$/, | |
}, | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
axios({ | |
method: 'get', | |
url: 'URL', | |
params: { | |
keyword: 'keyword' | |
}, | |
responseType: 'stream' | |
}) | |
.then(response => { | |
for (const key in response.headers) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* If used Promise all first error will go to catch block | |
* | |
* If no error occurs then the resolved values will be an array | |
with exact sequence of promise here e.g if run Promise.all([p1, p2, p3]) | |
output: [ 'one', 'two', 'three' ] | |
* | |
* If there is a setTimeout after all setTimeout execution will be done | |
* | |
* If there is a setTimeout, setImmediate or setTimeout 0 thoose will be executed after next tick |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { object, string, number, ValidationError } from '@hapi/joi'; | |
const schema = object({ | |
searchCode: string() | |
.required() | |
.label('Search code'), | |
id: number().required() | |
}), | |
messages = { | |
'alternatives.all': '{{#label}} does not match all of the required types', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class BaseError extends Error { | |
abstract status: number; | |
} | |
class ValidationError extends BaseError { | |
status: number = 422; | |
constructor(message?: string) { | |
super(message); | |
this.name = this.constructor.name; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example of array flat map alternative | |
const data = [ | |
{ | |
city: [ | |
{ | |
country: "Bhutan" | |
}, | |
{ | |
country: "Bhutan" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
POST tasks/_doc | |
{ | |
"title": "Goto ICCDRB", | |
"description": "I will goto ICCDRB with my mother for her urine test & ultrasonogram test", | |
"user": { | |
"id": 1, | |
"name": "Arif Mahmud Rana", | |
"email": "[email protected]" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {array, object, string, validate} from "joi"; | |
const schema = object({ | |
searchCode: string().required().label('Search code'), | |
primaryContact: object({ | |
mobileNumber: string() | |
.regex(/^\+?\d{7,13}$/) | |
.error(() => 'You must provide a valid Primary contact mobile number.') | |
.required() | |
.label('Primary contact mobile number') | |
}).required(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// custom toJSON example object | |
const a = { | |
id: 1, | |
name: 'ARIF', | |
toJSON() { | |
return JSON.stringify({id: this.id}) | |
} | |
} | |
const a = new A(); | |
const b = {...a} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const joi = require("joi"); | |
// const schema = joi.object({ | |
// roomIds: joi.array() | |
// .required() | |
// .min(1) | |
// .max(6) | |
// .sparse() | |
// .items(joi.string()) | |
// }).keys({ |
NewerOlder