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


TypeScript Boom.conflict函数代码示例

本文整理汇总了TypeScript中Boom.conflict函数的典型用法代码示例。如果您正苦于以下问题:TypeScript conflict函数的具体用法?TypeScript conflict怎么用?TypeScript conflict使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: 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

示例2: initPostSpacesApi

export function initPostSpacesApi(server: any, routePreCheckLicenseFn: any) {
  server.route({
    method: 'POST',
    path: '/api/spaces/space',
    async handler(request: any, reply: any) {
      const { SavedObjectsClient } = server.savedObjects;
      const spacesClient: SpacesClient = server.plugins.spaces.spacesClient.getScopedClient(
        request
      );

      const space = request.payload;

      try {
        return reply(await spacesClient.create(space));
      } catch (error) {
        if (SavedObjectsClient.errors.isConflictError(error)) {
          return reply(Boom.conflict(`A space with the identifier ${space.id} already exists.`));
        }
        return reply(wrapError(error));
      }
    },
    config: {
      validate: {
        payload: spaceSchema,
      },
      pre: [routePreCheckLicenseFn],
    },
  });
}
开发者ID:salihkardan,项目名称:kibana,代码行数:29,代码来源:post.ts

示例3: initPostSpacesApi

export function initPostSpacesApi(server: any, routePreCheckLicenseFn: any) {
  server.route({
    method: 'POST',
    path: '/api/spaces/space',
    async handler(request: any) {
      server.log(['spaces', 'debug'], `Inside POST /api/spaces/space`);
      const { SavedObjectsClient } = server.savedObjects;
      const spacesClient: SpacesClient = server.plugins.spaces.spacesClient.getScopedClient(
        request
      );

      const space = request.payload;

      try {
        server.log(['spaces', 'debug'], `Attempting to create space`);
        return await spacesClient.create(space);
      } catch (error) {
        if (SavedObjectsClient.errors.isConflictError(error)) {
          return Boom.conflict(`A space with the identifier ${space.id} already exists.`);
        }
        server.log(['spaces', 'debug'], `Error creating space: ${error}`);
        return wrapError(error);
      }
    },
    config: {
      validate: {
        payload: spaceSchema,
      },
      pre: [routePreCheckLicenseFn],
    },
  });
}
开发者ID:gingerwizard,项目名称:kibana,代码行数:32,代码来源:post.ts

示例4: 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

示例5: handler

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

  const user = new UserModel({
    userid: requestDoc.data.id,
    name: requestDoc.data.attributes.name,
  })

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

  const userResponse: UserResource.TopLevelDocument = {
    links: {
      self: `/users/${encodeURIComponent(user.userid)}`,
    },
    data: {
      type: 'users',
      id: user.userid,
      attributes: {
        name: user.name,
      },
      relationships: {
        team: {
          links: {
            self: `/users/${encodeURIComponent(user.userid)}/team`,
          },
          data: null,
        },
      },
    },
  }

  const eventBroadcaster: EventBroadcaster = req.server.app.eventBroadcaster
  eventBroadcaster.trigger('users_add', {
    userid: user.userid,
    name: user.name,
  }, req.logger)

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

示例6: handler

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

  const hack = new HackModel({
    hackid: slugify(requestDoc.data.attributes.name),
    name: requestDoc.data.attributes.name,
    members: [],
  })

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

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

  const eventBroadcaster: EventBroadcaster = req.server.app.eventBroadcaster
  eventBroadcaster.trigger('hacks_add', {
    hackid: hack.hackid,
    name: hack.name,
  }, req.logger)

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

示例7: handler

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

  const relationships = requestDoc.data.relationships
  let members: JSONApi.ResourceIdentifierObject[] = []
  let entries: JSONApi.ResourceIdentifierObject[] = []

  if (relationships) {
    if (relationships.members && relationships.members.data) {
      if (!Array.isArray(relationships.members.data)) {
        reply(Boom.badRequest())
        return
      }
      members = relationships.members.data
    }

    if (relationships.entries && relationships.entries.data) {
      if (!Array.isArray(relationships.entries.data)) {
        reply(Boom.badRequest())
        return
      }
      entries = relationships.entries.data
    }
  }

  const team = new TeamModel({
    teamid: slugify(requestDoc.data.attributes.name),
    name: requestDoc.data.attributes.name,
    motto: requestDoc.data.attributes.motto || null,
    members: [],
    entries: [],
  })

  let users: UserModel[] = []
  let hacks: HackModel[] = []

  if (members.length > 0) {
    users = await UserModel.find({
      userid: {
        $in: members.map((member) => member.id.toString()),
      },
    }, '_id userid name').exec()
    team.members = users.map((user) => user._id)
  }

  if (entries.length > 0) {
    hacks = await HackModel.find({
      hackid: {
        $in: entries.map((entry) => entry.id.toString()),
      },
    }, '_id hackid name').exec()
    team.entries = hacks.map((hack) => hack._id)
  }

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

  const teamResponse: TeamResource.TopLevelDocument = {
    links: {
      self: `/teams/${encodeURIComponent(team.teamid)}`,
    },
    data: {
      type: 'teams',
      id: team.teamid,
      attributes: {
        name: team.name,
        motto: team.motto,
      },
      relationships: {
        members: {
          links: { self: `/teams/${encodeURIComponent(team.teamid)}/members` },
          data: users.map((user) => ({ type: 'users', id: user.userid })),
        },
        entries: {
          links: { self: `/teams/${encodeURIComponent(team.teamid)}/entries` },
          data: hacks.map((hack) => ({ type: 'hacks', id: hack.hackid })),
        },
      },
    },
  }

  const eventBroadcaster: EventBroadcaster = req.server.app.eventBroadcaster
  eventBroadcaster.trigger('teams_add', {
    teamid: team.teamid,
    name: team.name,
    motto: team.motto,
    members: users.map((user) => ({ userid: user.userid, name: user.name })),
    entries: hacks.map((hack) => ({ hackid: hack.hackid, name: hack.name })),
  }, req.logger)

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


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