How to use the loopback-next/packages/loopback.api function in loopback-next

To help you get started, we’ve selected a few loopback-next examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github strongloop / loopback4-example-microservices / controllers / CustomerController.ts View on Github external
import {def} from './CustomerController.api';
import {api, inject} from 'loopback-next/packages/loopback';

let DataSource = require('../../loopback-datasource-juggler').DataSource;

let ds = new DataSource('CustomerDB', {
    "connector": "memory",
    "file": "data.json"
});

@api(def)
export class CustomerController {
   constructor() {
      var Customer = ds.define('Customer', {
       name: String,
     });
   }
   public async query() : Promise{
       var Customer = ds.define('Customer', {
        name: String,
       });
       var data = await Customer.find();
       console.log(data[0].customerNumber);
       return JSON.stringify({customerNumber: data[0].customerNumber, firstName: data[0].firstName});
   }
}
github strongloop / loopback4-example-microservices / services / facade / controllers / FacadeController.ts View on Github external
import {api} from 'loopback-next/packages/loopback';
import {def} from './FacadeController.api';
import {AccountRepository} from '../repositories/accounts';
import {CustomerRepository} from '../repositories/customer';
import {TransactionRepository} from '../repositories/transaction';
const bluebird =  require('bluebird');

@api(def)
export class FacadeController {
  async getSummary(accountNumber) : Promise {
    const accountRepository = new AccountRepository();
    const customerRepository = new CustomerRepository();
    const transactionRepository = new TransactionRepository();
    const accounts = await accountRepository.find(accountNumber);
    const summary = await bluebird.props ({
      account: accounts,
      customer: customerRepository.find(accounts.customerNumber),
      transaction: transactionRepository.find(accountNumber)
    });
    return Promise.resolve(JSON.stringify(summary));
  }
}

loopback-next

[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/strongloop/loopback) [![Build Status](https://img.shields.io/travis/rust-lang/rust.svg)](https://travis-ci.org/strongloop/loopback-next)

MIT
Latest version published 7 years ago

Package Health Score

69 / 100
Full package analysis

Similar packages