@nestjs/common#Headers TypeScript Examples
The following examples show how to use
@nestjs/common#Headers.
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: request.controller.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
@Post()
@Permissions('requests/create')
public async create(
@Headers('authorization') authorization: string,
@Body() request: RequestEntity,
@Req() req: Request
): Promise<any> {
const remoteAddress = req.headers['x-real-ip'] as string || "internal";
// first of all check for ban
if (await this.banService.findOne({
where: [
{ identifier: remoteAddress, expiresAt: MoreThan(new Date()) },
{ identifier: remoteAddress, expiresAt: IsNull() }
]
})) {
throw new NotAcceptableException('You have been banned from this radio');
}
if (await this.permissionService.hasPermission((req.user as any)?.uuid || req.headers.authorization, ['requests/ignore-timeout'])) {
return this.requestService.create({
requestOrigin: 'website',
...request,
requestContext: remoteAddress
});
}
if (await this.requestService.findRecent(remoteAddress)) {
throw new NotAcceptableException('Please wait before making another request');
}
return this.requestService.create({
requestOrigin: 'website',
...request,
requestContext: remoteAddress
});
}
Example #2
Source File: test-call.controller.ts From twilio-voice-notification-app with Apache License 2.0 | 6 votes |
/**
* POST /test-call
* Triggers a new call for testing purposes.
* @param from Caller number
* @param to Callee number
* @param message Message to deliver
*/
@UseGuards(AuthGuard)
@HttpCode(HttpStatus.OK)
@Post()
async makeTestCall(
@Body('from') from: string,
@Body('to') to: string,
@Body('message') message: string,
@Headers('referer') fullUrl: string,
): Promise<any> {
try {
const baseUrl = new URL(fullUrl);
const statusCallback = url.format({
protocol: baseUrl.protocol,
hostname: baseUrl.hostname,
pathname: '/api/test-call/callback',
});
return await this.testCallService.create(
to,
from,
message,
statusCallback,
);
} catch (error) {
throw new HttpException(
`Error: ${error.message}`,
HttpStatus.INTERNAL_SERVER_ERROR,
);
}
}
Example #3
Source File: ScryptaController.ts From tatum-blockchain-connector with MIT License | 6 votes |
@Post('/transaction')
async sendTransactionByAddressOrUtxo(@Body() body, @Headers() headers) {
if(body.fromAddress !== undefined && body.to !== undefined && headers['x-api-key'] !== undefined){
process.env.TATUM_API_KEY = headers['x-api-key']
return await this.scrypta.sendTransactionByAddressOrUtxo({fromAddress: body.fromAddress, to: body.to});
}else if(body.fromUTXO !== undefined && body.to !== undefined){
return await this.scrypta.sendTransactionByAddressOrUtxo({fromUTXO: body.fromUTXO, to: body.to});
}else{
return { message: "Please send all required parameter", failed: true }
}
}
Example #4
Source File: QuorumController.ts From tatum-blockchain-connector with MIT License | 6 votes |
@Post('/transaction')
@HttpCode(HttpStatus.OK)
async sendTransaction(@Body() body: TransferQuorum, @Headers() url: object) {
try {
return await this.service.sendTransaction(body, url[HEADER_ENDPOINT]);
} catch (e) {
throw new QuorumError(`Unexpected error occurred. Reason: ${e.message?.message || e.response?.data || e.message || e}`, 'quorum.error');
}
}
Example #5
Source File: FabricController.ts From tatum-blockchain-connector with MIT License | 6 votes |
@Post('/data')
async storeData(@Body() body: CreateRecord, @Headers() url: object) {
try {
if (body.chain === Currency.FABRIC) {
return await this.service.storeData(body.key, body.data, url[FABRIC_HEADER_ENDPOINT]);
}
} catch (e) {
throw new FabricError(`Unexpected error occurred. Reason: ${e.message?.message || e.response?.data || e.message || e}`, 'fabric.error');
}
throw new FabricError(`Incompatible chain.`, 'fabric.error');
}
Example #6
Source File: notification.controller.ts From office-hours with GNU General Public License v3.0 | 6 votes |
// Webhook from twilio
@Post('/phone/verify')
@Header('Content-Type', 'text/xml')
async verifyPhoneUser(
@Body() body: TwilioBody,
@Headers('x-twilio-signature') twilioSignature: string,
): Promise<string> {
const message = body.Body.trim().toUpperCase();
const senderNumber = body.From;
const twilioAuthToken = this.configService.get('TWILIOAUTHTOKEN');
const isValidated = twilio.validateRequest(
twilioAuthToken,
twilioSignature.trim(),
`${this.configService.get('DOMAIN')}/api/v1/notifications/phone/verify`,
body,
);
if (!isValidated) {
throw new UnauthorizedException(
ERROR_MESSAGES.notificationController.messageNotFromTwilio,
);
}
const messageToUser = await this.notifService.verifyPhone(
senderNumber,
message,
);
const MessagingResponse = twilio.twiml.MessagingResponse;
const twiml = new MessagingResponse();
twiml.message(messageToUser);
return twiml.toString();
}
Example #7
Source File: role.controller.ts From radiopanel with GNU General Public License v3.0 | 6 votes |
@Post()
@Permissions('roles/create')
@AuditLog('roles/create')
public create(@Body() role: Role, @Headers('x-tenant') tenant: string): Promise<Role> {
role.uuid = uuid.v4();
role.createdAt = new Date();
role.updatedAt = new Date();
return this.roleService.create(role);
}
Example #8
Source File: FabricController.ts From tatum-blockchain-connector with MIT License | 5 votes |
@Get('/data/:key')
async getData(@Param('key') key: string, @Headers() url: object) {
try {
return await this.service.getData(key, url[FABRIC_HEADER_ENDPOINT]);
} catch (e) {
throw new FabricError(`Unexpected error occurred. Reason: ${e.message?.message || e.response?.data || e.message || e}`, 'fabric.error');
}
}
Example #9
Source File: QuorumController.ts From tatum-blockchain-connector with MIT License | 5 votes |
@Post('/web3/:xApiKey')
@HttpCode(HttpStatus.OK)
async web3Driver(@Body() body: any, @Headers() url: object) {
return this.service.web3Method(body, url[HEADER_ENDPOINT]);
}
Example #10
Source File: QuorumController.ts From tatum-blockchain-connector with MIT License | 5 votes |
@Post('/account')
async generateAccount(@Body() body: AccountPassword, @Headers() url: object) {
try {
return await this.service.generateAccount(body.password, url[HEADER_ENDPOINT]);
} catch (e) {
throw new QuorumError(`Unexpected error occurred. Reason: ${e.message?.message || e.response?.data || e.message || e}`, 'quorum.error');
}
}
Example #11
Source File: QuorumController.ts From tatum-blockchain-connector with MIT License | 5 votes |
@Get('/block/current')
async getInfo(@Headers() url: object) {
try {
return await this.service.getBlockChainInfo(url[HEADER_ENDPOINT]);
} catch (e) {
throw new QuorumError(`Unexpected error occurred. Reason: ${e.message?.message || e.response?.data || e.message || e}`, 'quorum.error');
}
}
Example #12
Source File: QuorumController.ts From tatum-blockchain-connector with MIT License | 5 votes |
@Get('/block/:hashOrHeight')
async getBlock(@Param('hashOrHeight') hashOrHeight: string, @Headers() url: object) {
try {
return await this.service.getBlock(hashOrHeight, url[HEADER_ENDPOINT]);
} catch (e) {
throw new QuorumError(`Unexpected error occurred. Reason: ${e.message?.message || e.response?.data || e.message || e}`, 'quorum.error');
}
}
Example #13
Source File: QuorumController.ts From tatum-blockchain-connector with MIT License | 5 votes |
@Post('/account/:address/unlock')
async unlockAccount(@Body() body: AccountPassword, @Param() path: PathAddress, @Headers() url: object) {
try {
return await this.service.unlockAccount(path.address, body.password, url[HEADER_ENDPOINT]);
} catch (e) {
throw new QuorumError(`Unexpected error occurred. Reason: ${e.message?.message || e.response?.data || e.message || e}`, 'quorum.error');
}
}
Example #14
Source File: QuorumController.ts From tatum-blockchain-connector with MIT License | 5 votes |
@Get('/transaction/:txId')
async getTransaction(@Param() path: PathTxId, @Headers() url: object) {
try {
return await this.service.getTransaction(path.txId, url[HEADER_ENDPOINT]);
} catch (e) {
throw new QuorumError(`Unexpected error occurred. Reason: ${e.message?.message || e.response?.data || e.message || e}`, 'quorum.error');
}
}
Example #15
Source File: QuorumController.ts From tatum-blockchain-connector with MIT License | 5 votes |
@Get('/transaction/:txId/receipt')
async getTransactionReceipt(@Param() path: PathTxId, @Headers() url: object) {
try {
return await this.service.getTransactionReceipt(path.txId, url[HEADER_ENDPOINT]);
} catch (e) {
throw new QuorumError(`Unexpected error occurred. Reason: ${e.message?.message || e.response?.data || e.message || e}`, 'quorum.error');
}
}
Example #16
Source File: song.controller.ts From radiopanel with GNU General Public License v3.0 | 5 votes |
@Get('sync')
public async sync(@Headers('authorization') authorization: string): Promise<any> {
return this.songService.handleCron();
}
Example #17
Source File: broadcast.controller.ts From twilio-voice-notification-app with Apache License 2.0 | 5 votes |
/**
* POST /broadcasts/
* Creates a new Notification
* @param friendlyName The name of the notification
* @param from Caller number
* @param to Comma-separated list of numbers to call
* @param message Message to deliver
*/
@UseGuards(AuthGuard)
@Post()
async createBroadcast(
@Body('friendlyName') friendlyName: string,
@Body('from') from: string,
@Body('to') to: string,
@Body('message') message: string,
@Headers('referer') fullUrl: string,
@Res() response: Response,
) {
const baseUrl = new URL(fullUrl);
// Creates the notification Resource and stores it in DB
const broadcastId = await this.broadcastService.create(
friendlyName,
from,
message,
);
// It uses referer URL from headers to build the voiceUrl callback param
// when creating the Call resource.
const statusCallback = url.format({
protocol: baseUrl.protocol,
hostname: baseUrl.hostname,
pathname: '/api/broadcasts/callback',
query: {
passCode: this.passCode,
},
});
// Communication with Twilio for calls creation and subsequent INSERTS in
// database happen in background after the Response has been sent.
// noinspection ES6MissingAwait
this.broadcastService.makeCalls(
broadcastId,
from,
message,
to.split(','),
statusCallback,
);
return response.json({ broadcastId });
}
Example #18
Source File: api-key.controller.ts From radiopanel with GNU General Public License v3.0 | 5 votes |
@Get('sync')
public async sync(@Headers('authorization') authorization: string): Promise<any> {
return this.apiKeyService.handleCron();
}