npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pg-challenges

v4.1.2

Published

Reusable challenges-system build with Postgres and Hapi.

Downloads

92

Readme

Challenges

Build Status codecov

Pre-requisites:

  • Create a challenges_test and challenges database:

    CREATE DATABASE challenges;
    CREATE DATABASE challenges_test
  • Initialise tables and populate your database by running

    npm run db
  • creates a 'Challenges' table

A plugin which exposes the following functions on the request.server.methods.pg.challengs object:

add(challengeObject, cb)

function to add challenge to pre-existing challenge table challengeObject:

{
  title: 'Tea',
  description: 'With milk',
  org_id: 1,
  creator_id: 1,
  active: true
}

Returns [{ id: x }] if challenge was successfully added, where x is assigned by postgres. Returns an error if unsuccessful.

edit(challengeId, updatedObject, cb)

function to edit the title and description of a pre-existing challenge. where: challengeId = integer and id of existing challenge that needs to be updated updatedObject takes the following form:

{
  title: 'Two teas',
  description: 'With milk and one sugar',
}

Returns [] if challenge was successfully. Returns an error if unsuccessful.

getById(id, cb)

function to get a specific challenge, and associated tags, id: Integer

returns:

{
  id: 2,
  title: 'Challenge Number 2',
  description: 'How can I...?',
  org_id: 1,
  org_name: 'Apple'
  creator_id: 3,
  tags: [ { id: 2, name: 'Corporate' } ] || [] // if no tags
}

or an empty array [] if no challenge was found.

getByTag(id, cb)

function to get all challenges that contain a certain tag id: Integer if we want to filter by a tag id or false if we do not want to filter

If a tag id is given, returns:

{ filter: { id: 69, name: 'Design for disassembly' },
  challenges:
   [ { id: 4,
       date: '2016-12-07 15:36:24.636112+00',
       title: 'Challenge Number 4',
       description: 'Who should I...?',
       org_id: 2,
       shared_by: 'dwyl',
       tags:
        [
          { tag_id: 9, tag_name: 'Automotive and Transport Manufacturing' },
          { tag_id: 11, tag_name: 'Chemicals' },
          { tag_id: 60, tag_name: 'Secondary education' }
        ]
      },
     { id: 7,
       date: '2016-12-07 15:36:24.636112+00',
       title: 'Challenge Number 7',
       description: 'Is it possible to...?',
       org_id: 4,
       shared_by: 'EMF',
       tags: null // if no tags have been attached to the challenge
     },
      ...
    ]
}

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

filter_tag: undefined

checkEditable(userId, chalId, cb)

returns Boolean If user and belongs to the org that created the challenge, return true; otherwise false.

getMatchingOrgs(chal_id, cb)

Returns an array of orgs. Empty array if no orgs share active tags with the given challenge. The orgs are ordered by number of tags that they matched the challenge with.

[
  {
    "name": "Asda",
    "id": 6,
    "tags": [
      {
        "tag_name": "Automotive and Transport Manufacturing",
        "tag_id": 9
      },
      {
        "tag_name": "Chemicals",
        "tag_id": 11
      }
    ]
  },
  {
    "name": "EMF",
    "id": 4,
    "tags": [
      {
        "tag_name": "Automotive and Transport Manufacturing",
        "tag_id": 9
      }
    ]
  }
]

getArchived(org_id, cb)

Returns an array of challenge objects for a given organisation.

{
  id: 1,
  title: 'Challenge Number 1',
  description: 'What can I...?',
  org_id: 1,
  creator_id: 3
}