Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pg-insights

Package Overview
Dependencies
Maintainers
3
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pg-insights

Reusable insight-system built with Postgres and Hapi.

  • 0.2.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

Insights

Build Status codecov

Pre-requisites:

  • Create an insights and insights_test database:
    CREATE DATABASE insights;
    CREATE DATABASE insights_test
    

This plugin exposes the following functions on the request.server.methods.pg.insights object:

getById(insightId, cb)

function to return the details of a specific insight, where insightId is the ID of the insight to retrieve.

The insight details take the following format:

[{
  id: 1,
  date: 2016-12-23T11:27:41.760Z,
  title: 'Insight Number 1',
  url: 'https://....',
  active: true,
  tags: [
  {
    tag_id: 8,
    tag_name: 'Agriculture'
  }, {
    tag_id: 22,
    tag_name: 'Telecommunications'
  }, {
  ...
}]

edit(insightObj, cb)

function to add a new insight, where insightObj takes the form:

{
  title: 'Insight Title',
  url: 'www.ce100-insight-url.com',
  doctype: '.pdf',
  author: 'EMF',
  org_id: null,
  creator_id: 1,
  resource: true
}

On the successful save, the new insight's ID (generated by postgres) is returned.

add(insightObj, cb)

function to add a new insight, where insightObj takes the form:

{
  title: 'Insight Title',
  url: 'www.ce100-insight-url.com',
  type: 'REPORT',
  author: 'EMF',
  org_id: null,
  creator_id: 1,
  resource: true,
  active: true
}

On the successful save, the new insight's ID (generated by postgres) is returned.

browse(activeOnly, filterTag, cb)

function to browse all active (and inactive) insights, with the option to filter by a certain tag id. The parameters take the following values respectively:

  • activeOnly = Boolean.
    • true to return active insights only.
    • false to return all active and inactive insights.
  • filterTag:
    • Integer if we want to filter by a tag id
    • false if we do not want to filter

If a tag id is given, returns:

{ filter: { id: 69, name: 'Design for disassembly' },
  insights:
  [{
    id: 1,
    date: 2016-12-23T11:27:41.760Z,
    title: 'Insight Number 1',
    url: 'https://....',
    active: true,
    tags: [
    {
      tag_id: 8,
      tag_name: 'Agriculture'
    }, {
      tag_id: 22,
      tag_name: 'Telecommunications'
    }, {
  ...
  }]
}

If false is given, returns the same shape, but with

filter_tag: undefined

toggle(insightId, cb)

function to set an existing insight to be active or inactive. insightId specifies the ID of the insight to toggle.

getResources(activeOnly, cb)

function to return the details of active and inactive resources. The activeOnly parameter is a Boolean. Set it to:

  • true to return active insights only.
  • false to return all active and inactive insights.

The resources take the following format:

[{
  id: 1,
  title: 'Insight Number 1',
  url: 'https://....',
  author: 'Kamala Khan',
  type: 'REPORT',
  active: true
  }, {
  ...
}]

Note that the active field is not returned when activeOnly === true, as all resources returned will be active.

FAQs

Package last updated on 25 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc