How to use the @loopback/rest.operation function in @loopback/rest

To help you get started, we’ve selected a few @loopback/rest 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 IBM / blockchainbean2 / web-app / src / controllers / world-state.controller.ts View on Github external
console.log(result)
    //check if key does not exist, if so, send 404
    if ( result.indexOf( errorMessage ) > -1 ) {
      result = new Error(result);
    }
    return result 
  }

  /**
   * 
   * 

   * @param key 
   * @returns Request was successful
   */
  @operation('delete', '/worldstate/{key}')
  async deleteByKey(@param({ name: 'key', in: 'path' }) key: string): Promise {
    let networkObj = await blockchainClient.connectToNetwork();
    let result = await blockchainClient.deleteByKey(networkObj.contract, key);
    console.log(result)
    // var rez = JSON.parse(result.toString());
    console.log('before rez: ')
    console.log(result)
    //check if key does not exist, if so, send 404
    if ( result.indexOf( errorMessage ) > -1 ) {
      result = new Error(result);
    }
    return result 
  }

}
github strongloop / loopback-next / packages / v3compat / src / remoting / rest-adapter.ts View on Github external
...args: OperationArgs
    ) {
      if (!sharedMethod.isStatic) {
        // TODO: invoke sharedCtor to obtain the model instance
        throw new HttpErrors.NotImplemented(
          'Instance-level shared methods are not supported yet.',
        );
      }

      return this.invokeStaticMethod(sharedMethod, args);
    };

    debug('    %s %s %j', verb, path, spec);

    // Define OpenAPI Spec Operation for the shared method
    operation(
      convertVerb(verb),
      joinUrlPaths(this.restApiRoot, convertPathFragments(path)),
      spec,
    )(controllerClass.prototype, key, {});
  }
}
github IBM / blockchainbean2 / web-app / src / controllers / grower.controller.ts View on Github external
/**
 * The controller class is generated from OpenAPI spec with operations tagged
 * by Grower
 * A participant named Grower
 */
export class GrowerController {
  constructor() { }

  /**
   *
   *

   * @param requestBody Model instance data
   * @returns Request was successful
   */
  @operation('post', '/Grower', {
    responses: {
      '200': {
        description: 'ResponseMessage model instance',
        content: { 'application/json': { schema: { 'x-ts-type': ResponseMessage } } },
      },
    },
  })
  async growerCreate(@requestBody() requestBody: Grower): Promise {
    try {
      let networkObj = await blockchainClient.connectToNetwork();
      console.log('request body: ')
      console.log(requestBody)
      let dataForAddMember = {
        function: 'addMember',
        id: requestBody.growerId,
        organization: requestBody.organization,
github IBM / blockchainbean2 / web-app / src / controllers / submit-packing-list.controller.ts View on Github external
/**
 * The controller class is generated from OpenAPI spec with operations tagged
 * by submitPackingList
 * A transaction named submitPackingList
 */
export class SubmitPackingListController {
  constructor() { }

  /**
   *
   *

   * @param requestBody Model instance data
   * @returns Request was successful
   */
  @operation('post', '/submitPackingList', {
    responses: {
      '200': {
        description: 'ResponseMessage model instance',
        content: { 'application/json': { schema: { 'x-ts-type': ResponseMessage } } },
      },
    },
  })
  async submitPackingListCreate(@requestBody() requestBody: SubmitPackingList): Promise {

    try {

      let networkObj = await blockchainClient.connectToNetwork();
      console.log('newtork obj: ')
      console.log(networkObj)
      let dateStr = new Date().toDateString();
github IBM / blockchainbean2 / web-app / src / controllers / pour-cup.controller.ts View on Github external
/**
 * The controller class is generated from OpenAPI spec with operations tagged
 * by pourCup
 * A transaction named pourCup
 */
export class PourCupController {
  constructor() { }

  /**
   *
   *

   * @param requestBody Model instance data
   * @returns Request was successful
   */
  @operation('post', '/pourCup', {
    responses: {
      '200': {
        description: 'ResponseMessage model instance',
        content: { 'application/json': { schema: { 'x-ts-type': ResponseMessage } } },
      },
    },
  })
  async pourCupCreate(@requestBody() requestBody: PourCup): Promise {

    try {
      console.log('pourCup, requestBody: ')
      console.log(requestBody)

      let networkObj = await blockchainClient.connectToNetwork();
      console.log('newtork obj: ')
      console.log(networkObj)
github johnwalicki / IoT-AssetTracking-Perishable-Network-Blockchain / Blockchain / web-app / app / src / controllers / accel-reading.controller.ts View on Github external
return responseMessage;
  } catch (error) {
    let responseMessage: ResponseMessage = new ResponseMessage({ message: error, statusCode: '400' });
    return responseMessage;
  }
}


  /**
   * 
   * 

   * @param id Model id
   * @returns ResponseMessage with readings or error message
   */
  @operation('get', '/AccelReading/{id}',{
    responses: {
      '200': {
        description: 'Response model instance',
        content: { 'application/json': { schema: { 'x-ts-type': ResponseMessage } } },
      },
    },
})
  async accelReadingFindById(@param({name: 'id', in: 'path'}) id: string): Promise {
    try{
      let networkObj = await blockChainClient.connectToNetwork();
      let shipmentString = await blockChainClient.getShipmentByTransactionId(networkObj.contract, id);
      var shipmentJSON = JSON.parse(shipmentString);
      let repsonseMesssage: ResponseMessage = new ResponseMessage({message:`AccelReadings for shipment ${id}`, objectlist: shipmentJSON.AccelReadings, statusCode:'200'});
      return repsonseMesssage;

    } catch(error){
github johnwalicki / IoT-AssetTracking-Perishable-Network-Blockchain / Blockchain / web-app / app / src / controllers / grower.controller.ts View on Github external
@operation('head', '/Grower/{id}')
  async growerExists(@param({name: 'id', in: 'path'}) id: string): Promise<{
  exists?: boolean;
}> {
    throw new Error('Not implemented');
  }

  /**
   * 
   * 

   * @param id Model id
   * @param filter Filter defining fields and include - must be a JSON-encoded string ({"something":"value"})
   * @returns Request was successful
   */
  @operation('get', '/Grower/{id}')
  async growerFindById(@param({name: 'id', in: 'path'}) id: string, @param({name: 'filter', in: 'query'}) filter: string): Promise {
    throw new Error('Not implemented');
  }

  /**
   * 
   * 

   * @param requestBody Model instance data
   * @param id Model id
   * @returns Request was successful
   */
  @operation('put', '/Grower/{id}')
  async growerReplaceById(@requestBody() requestBody: Grower, @param({name: 'id', in: 'path'}) id: string): Promise {
    throw new Error('Not implemented');
  }
github johnwalicki / IoT-AssetTracking-Perishable-Network-Blockchain / Blockchain / web-app / app / src / controllers / importer.controller.ts View on Github external
* @param filter Filter defining fields, where, include, order, offset, and limit - must be a JSON-encoded string ({"something":"value"})
   * @returns Request was successful
   */
  @operation('get', '/Importer')
  async importerFind(@param({name: 'filter', in: 'query'}) filter: string): Promise {
    throw new Error('Not implemented');
  }

  /**
   * 
   * 

   * @param id Model id
   * @returns Request was successful
   */
  @operation('head', '/Importer/{id}')
  async importerExists(@param({name: 'id', in: 'path'}) id: string): Promise<{
  exists?: boolean;
}> {
    throw new Error('Not implemented');
  }

  /**
   * 
   * 

   * @param id Model id
   * @param filter Filter defining fields and include - must be a JSON-encoded string ({"something":"value"})
   * @returns Request was successful
   */
  @operation('get', '/Importer/{id}')
  async importerFindById(@param({name: 'id', in: 'path'}) id: string, @param({name: 'filter', in: 'query'}) filter: string): Promise {
github johnwalicki / IoT-AssetTracking-Perishable-Network-Blockchain / Blockchain / web-app / app / src / controllers / shipment.controller.ts View on Github external
* An asset named Shipment
 */
export class ShipmentController {
  constructor() {}



  /**
   * 
   * 

   * @param id Model id
   * @param filter Filter defining fields and include - must be a JSON-encoded string ({"something":"value"})
   * @returns Request was successful
   */
  @operation('get', '/Shipment/{shipmentId}')
  async shipmentFindById(@param({name: 'shipmentId', in: 'path'}) shipmentId: string): Promise {
    
    try{
      let networkObj = await blockChainClient.connectToNetwork();
      let shipment: Shipment = await blockChainClient.getShipmentByTransactionId(networkObj.contract, shipmentId);

      return shipment;
    } catch (error) {
      let responseMessage: ResponseMessage = new ResponseMessage({ message: error, statusCode: '400' });
      throw responseMessage;
    }
  }
}
github johnwalicki / IoT-AssetTracking-Perishable-Network-Blockchain / Blockchain / web-app / app / src / controllers / temperature-reading.controller.ts View on Github external
} catch (error) {
    let responseMessage: ResponseMessage = new ResponseMessage({ message: error, statusCode: '400' });
    return responseMessage;
  }
}



 /**
   * 
   * 

   * @param id Model id
   * @returns ResponseMessage with readings or error message
   */
  @operation('get', '/TemperatureReading/{id}',{
    responses: {
      '200': {
        description: 'Response model instance',
        content: { 'application/json': { schema: { 'x-ts-type': ResponseMessage } } },
      },
    },
  })
  async TemperatureReadingFindById(@param({name: 'id', in: 'path'}) id: string): Promise {
    try{
      let networkObj = await blockChainClient.connectToNetwork();
      let shipmentString = await blockChainClient.getShipmentByTransactionId(networkObj.contract, id);
      var shipmentJSON = JSON.parse(shipmentString);
      let repsonseMesssage: ResponseMessage = new ResponseMessage({message:`TemperatureReadings for shipment ${id}`, objectlist: shipmentJSON.temperatureReadings, statusCode:'200'});
      return repsonseMesssage;

    } catch(error){