当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript IReply.default方法代码示例

本文整理汇总了TypeScript中hapi.IReply.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript IReply.default方法的具体用法?TypeScript IReply.default怎么用?TypeScript IReply.default使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hapi.IReply的用法示例。


在下文中一共展示了IReply.default方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: handler

export default async function handler(req: Request, reply: IReply) {
  const { hackId: hackid } = req.params

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

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

  const challenges = hack.challenges.map((challenge): JSONApi.ResourceIdentifierObject => ({
    type: 'challenges',
    id: challenge.challengeid,
  }))

  const includedChallenges = hack.challenges.map((challenge): ChallengeResource.ResourceObject => ({
    links: { self: `/challenges/${challenge.challengeid}` },
    type: 'challenges',
    id: challenge.challengeid,
    attributes: { name: challenge.name },
  }))

  const challengesResponse: HackChallengesRelationship.TopLevelDocument = {
    links: { self: `/hacks/${encodeURIComponent(hack.hackid)}/challenges` },
    data: challenges,
    included: includedChallenges,
  }

  reply(challengesResponse)
}
开发者ID:TechNottingham,项目名称:Hack24-API,代码行数:33,代码来源:get-hack-challenges.ts

示例2: handler

export default async function handler(req: Request, reply: IReply) {
  const requestDoc: ChallengeResource.TopLevelDocument = req.payload

  const challenge = new ChallengeModel({
    challengeid: slugify(requestDoc.data.attributes.name),
    name: requestDoc.data.attributes.name,
    members: [],
  })

  try {
    await challenge.save()
  } catch (err) {
    if (err.code === MongoDBErrors.E11000_DUPLICATE_KEY) {
      reply(Boom.conflict('Challenge already exists'))
      return
    }
    throw err
  }

  const challengeResponse: ChallengeResource.TopLevelDocument = {
    links: {
      self: `/challenges/${encodeURIComponent(challenge.challengeid)}`,
    },
    data: {
      type: 'challenges',
      id: challenge.challengeid,
      attributes: {
        name: challenge.name,
      },
    },
  }

  reply(challengeResponse).code(201)
}
开发者ID:TechNottingham,项目名称:Hack24-API,代码行数:34,代码来源:create-challenge.ts

示例3: handler

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)
}
开发者ID:TechNottingham,项目名称:Hack24-API,代码行数:25,代码来源:get-hack.ts

示例4: handler

export default async function handler(req: Request, reply: IReply) {
  const { challengeId: challengeid } = req.params

  const challenge = await ChallengeModel
    .findOne({ challengeid }, 'challengeid name')
    .exec()

  if (challenge === null) {
    reply(Boom.notFound('Challenge not found'))
    return
  }

  const challengeResponse: ChallengeResource.TopLevelDocument = {
    links: { self: `/challenges/${encodeURIComponent(challenge.challengeid)}` },
    data: {
      type: 'challenges',
      id: challenge.challengeid,
      attributes: {
        name: challenge.name,
      },
    },
  }

  reply(challengeResponse)
}
开发者ID:TechNottingham,项目名称:Hack24-API,代码行数:25,代码来源:get-challenge.ts

示例5: handler

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)
}
开发者ID:TechNottingham,项目名称:Hack24-API,代码行数:33,代码来源:get-team-entries.ts

示例6: handler

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

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

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

  const members = team.members.map((member): JSONApi.ResourceIdentifierObject => ({
    type: 'users',
    id: member.userid,
  }))

  const includedUsers = team.members.map((member): UserResource.ResourceObject => ({
    links: { self: `/users/${member.userid}` },
    type: 'users',
    id: member.userid,
    attributes: { name: member.name },
  }))

  const membersResponse: TeamMembersRelationship.TopLevelDocument = {
    links: { self: `/teams/${encodeURIComponent(team.teamid)}/members` },
    data: members,
    included: includedUsers,
  }

  reply(membersResponse)
}
开发者ID:TechNottingham,项目名称:Hack24-API,代码行数:33,代码来源:get-team-members.ts

示例7: handler

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()
}
开发者ID:TechNottingham,项目名称:Hack24-API,代码行数:60,代码来源:add-team-entries.ts

示例8: handler

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

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

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

  const userIdsToAdd = requestDoc.data.map((user) => user.id)
  const existingUserIds = userIdsToAdd.filter((userIdToAdd) => team.members.some((actualMember) => actualMember.userid === userIdToAdd))

  if (existingUserIds.length > 0) {
    reply(Boom.badRequest('One or more users are already members of this team'))
    return
  }

  const users = await UserModel
    .find({ userid: { $in: userIdsToAdd } }, 'userid name')
    .exec()

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

  const userObjectIds = users.map((user) => user._id)

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

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

  team.members = team.members.concat(users.map((user) => user._id))

  await team.save()

  const eventBroadcaster: EventBroadcaster = req.server.app.eventBroadcaster
  users.forEach((user) => {
    eventBroadcaster.trigger('teams_update_members_add', {
      teamid: team.teamid,
      name: team.name,
      member: {
        userid: user.userid,
        name: user.name,
      },
    }, req.logger)
  })

  reply()
}
开发者ID:TechNottingham,项目名称:Hack24-API,代码行数:60,代码来源:add-team-members.ts

示例9: handler

export default async function handler(request: Request, reply: IReply) {
  const requestDoc: AttendeeResource.TopLevelDocument = request.payload

  const attendee = new AttendeeModel({
    attendeeid: requestDoc.data.id,
  })

  try {
    await attendee.save()
  } catch (err) {
    if (err.code === MongoDBErrors.E11000_DUPLICATE_KEY) {
      reply(Boom.conflict('Attendee already exists'))
      return
    }
    throw err
  }

  const attendeeResponse: AttendeeResource.TopLevelDocument = {
    links: { self: `/attendees/${encodeURIComponent(attendee.attendeeid)}` },
    data: {
      type: 'attendees',
      id: attendee.attendeeid,
    },
  }

  reply(attendeeResponse).code(201)
}
开发者ID:TechNottingham,项目名称:Hack24-API,代码行数:27,代码来源:create-attendee.ts

示例10: reply

export async function updateAccount(server: Server, request: Request, reply: IReply)
{
    const id = request.params["id"];
    const apiKey = request.auth.credentials.apiKey;
    const accountToUpdate: Account = request.payload;
    let dbAccount: Account;

    // Get the original account
    try
    {
        dbAccount = await Accounts.findByApiKey(apiKey);

        // Only update the account if the ApiKey and Id match.
        if (!dbAccount || dbAccount._id !== id || dbAccount.apiKey !== apiKey)
        {
            return reply(notFound("No account find with that id and API key combination."));
        }
    }
    catch (e)
    {
        console.error("Failed to retrieve account when updating.", e);

        return reply(boom(e));
    }

    // Transfer update props to the dbAccount
    for (let prop in accountToUpdate)
    {
        dbAccount[prop] = accountToUpdate[prop];
    }

    // Never update the account's ID or apiKey
    dbAccount._id = id;
    dbAccount.apiKey = apiKey;

    try
    {
        const update = await Accounts.Database.put(accountToUpdate);

        if (!update.ok)
        {
            console.error("Failed to update account.", update);

            return reply(expectationFailed("Failed to update account."));
        }
        
        dbAccount._rev = update.rev;
    }
    catch (e)
    {
        console.error("Failed to update account.", e);

        return reply(boom(e));
    }

    return reply(dbAccount);
}
开发者ID:nozzlegear,项目名称:stages-api,代码行数:57,代码来源:accounts-routes.ts


注:本文中的hapi.IReply.default方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。