Beispiel #1
0
 getPostByPostId(postId).then(post => {
     if (!post) {
         reply(boom.notFound());
         return;
     }
     let host = request.headers['host'];
     let protocol = getProtocolByHost(host);
     let postJSON = post.toJSON();
     if (postJSON.permalink && postJSON.permalink !== 'undefined') {
         let POST_URL = `${protocol}://${host}${postJSON.permalink}`;
         reply.redirect(POST_URL);
     } else {
         reply(boom.notFound());
     }
 }).catch((err: Error) => {
Beispiel #2
0
 getPostByPostId(postId).then(post => {
     if (!post) {
         reply(boom.notFound());
         return;
     }
     reply({ data: post.toJSON() });
 }).catch((err: Error) => {
Beispiel #3
0
export function initDeleteSpacesApi(server: any, routePreCheckLicenseFn: any) {
  server.route({
    method: 'DELETE',
    path: '/api/spaces/space/{id}',
    async handler(request: any, reply: any) {
      const { SavedObjectsClient } = server.savedObjects;
      const spacesClient: SpacesClient = server.plugins.spaces.spacesClient.getScopedClient(
        request
      );

      const id = request.params.id;

      let result;

      try {
        result = await spacesClient.delete(id);
      } catch (error) {
        if (SavedObjectsClient.errors.isNotFoundError(error)) {
          return reply(Boom.notFound());
        }
        return reply(wrapError(error));
      }

      return reply(result).code(204);
    },
    config: {
      pre: [routePreCheckLicenseFn],
    },
  });
}
 this.userRepository.findById(id).then((user: IUser) => {
   if (user) {
     reply(user);
   } else {
     reply(Boom.notFound());
   }
 }).catch((error) => {
 return getById(id).then(item => {
   if (!item) {
     Sentry.captureMessage(`Portfolio item does not exist: ${id}`);
     return next(boom.notFound(`Portfolio item does not exist: ${id}`));
   }
   return res.json(item);
 });
 this.doorRepository.findById(id).then((door: IDoor) => {
   if (door) {
     reply(door);
   } else {
     reply(Boom.notFound());
   }
 }).catch((error) => {
export default async function handler(req: Request, reply: IReply) {
  const { teamId: teamid } = req.params
  const requestDoc: TeamEntriesRelationship.TopLevelDocument = req.payload

  const team = await TeamModel
    .findOne({ teamid }, 'teamid name entries')
    .populate('entries', 'hackid')
    .exec()

  if (team === null) {
    reply(Boom.notFound('Team not found'))
    return
  }

  const hackIdsToAdd = requestDoc.data.map((hack) => hack.id)
  const existingHackIds = hackIdsToAdd.filter((hackIdToAdd) => team.entries.some((actualhack) => actualhack.hackid === hackIdToAdd))

  if (existingHackIds.length > 0) {
    reply(Boom.badRequest('One or more hacks are already entries of this team'))
    return
  }

  const hacks = await HackModel
    .find({ hackid: { $in: hackIdsToAdd } }, 'hackid name')
    .exec()

  if (hacks.length !== hackIdsToAdd.length) {
    reply(Boom.badRequest('One or more of the specified hacks could not be found'))
    return
  }

  const hackObjectIds = hacks.map((hack) => hack._id)

  const teams = await TeamModel
    .find({ entries: { $in: hackObjectIds } }, 'teamid')
    .exec()

  if (teams.length > 0) {
    reply(Boom.badRequest('One or more of the specified hacks are already in a team'))
    return
  }

  team.entries = team.entries.concat(hacks.map((hack) => hack._id))

  await team.save()

  const eventBroadcaster: EventBroadcaster = req.server.app.eventBroadcaster
  hacks.forEach((hack) => {
    eventBroadcaster.trigger('teams_update_entries_add', {
      teamid: team.teamid,
      name: team.name,
      entry: {
        hackid: hack.hackid,
        name: hack.name,
      },
    }, req.logger)
  })

  reply()
}
 getPost(postSlug, 'career').then(job => {
     if (!job) {
         reply(boom.notFound());
     }
     let jobJSON = job.toJSON();
     reply.view('post', { title: jobJSON.title, post: jobJSON }, { layout: 'hero-layout' });
 }).catch((err: Error) => {
Beispiel #9
0
export default async function handler(req: Request, reply: IReply) {
  const { hackId: hackid } = req.params

  const hack = await HackModel
    .findOne({ hackid }, 'hackid name')
    .exec()

  if (hack === null) {
    reply(Boom.notFound('Hack not found'))
    return
  }

  const hackResponse: HackResource.TopLevelDocument = {
    links: { self: `/hacks/${encodeURIComponent(hack.hackid)}` },
    data: {
      type: 'hacks',
      id: hack.hackid,
      attributes: {
        name: hack.name,
      },
    },
  }

  reply(hackResponse)
}
export default async function handler(req: Request, reply: IReply) {
  const { teamId: teamid } = req.params

  const team = await TeamModel
    .findOne({ teamid }, 'teamid entries')
    .populate('entries', 'hackid name')
    .exec()

  if (team === null) {
    reply(Boom.notFound('Team not found'))
    return
  }

  const entries = team.entries.map((hack): JSONApi.ResourceIdentifierObject => ({
    type: 'hacks',
    id: hack.hackid,
  }))

  const includedHacks = team.entries.map((hack): HackResource.ResourceObject => ({
    links: { self: `/hacks/${hack.hackid}` },
    type: 'hacks',
    id: hack.hackid,
    attributes: { name: hack.name },
  }))

  const entriesResponse: TeamEntriesRelationship.TopLevelDocument = {
    links: { self: `/teams/${encodeURIComponent(team.teamid)}/entries` },
    data: entries,
    included: includedHacks,
  }

  reply(entriesResponse)
}