В nest-контроллере используйте @Query()
/ @Body()
/ @Headers()
, декоратор без аргумента вернет объект javascript со значением ключа.
, например:
// request url: http://example.com/path-foo/path-bar?qf=1&qb=2
@Post(':foo/:bar')
async function baz(@Query() query,@Param() param) {
const keys = Object.keys(query); // ['qf', 'qb']
const vals = Object.values(query); // ['1', '2']
const pairs = Object.entries(query); // [['qf','1'],['qb','2']]
const params = Object.entries(param); // [['foo','path-foo'],['bar','path-bar']]
// these are all iterate able array
// so you can use any Array's built-in function
// e.g. for / forEach / map / filter ...
}
ссылка:
Объект
Object.keys ()
Object.values ()
Object.entries ()
// sample object
const obj = {
foo: 'this is foo',
bar: 'this is bar',
baz: 'this is baz',
};
Object.keys(obj);
Object.values(obj);
Object.entries(obj);
/**
* return iterable array:
*
* ['foo', 'bar', 'baz']
*
* ['this is foo', 'this is bar', 'this is baz']
*
* [
* ['foo', 'this is foo']
* ['bar', 'this is bar']
* ['baz', 'this is baz']
* ]
*/