{"record":{"id":"4dbeea9470700148","repo":"hcengineering/platform","slug":"type-and-value-are-required","errorCode":null,"errorMessage":"Type and value are required","messagePattern":"Type and value are required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/account/src/collections/mongo.ts","lineNumber":256,"sourceCode":"\n    return res.map((acc: Account) => this.convertToObj(acc))\n  }\n\n  async findOne (query: Query<Account>): Promise<Account | null> {\n    const res = await this.collection.findOne<Account>(getFilteredQuery(query) as Filter<Account>)\n\n    return res !== null ? this.convertToObj(res) : null\n  }\n}\n\nexport class SocialIdMongoDbCollection extends MongoDbCollection<SocialId, '_id'> implements DbCollection<SocialId> {\n  constructor (db: Db) {\n    super('socialId', db, '_id')\n  }\n\n  async insertOne (data: Partial<SocialId>): Promise<any> {\n    if (data.type === undefined || data.value === undefined) {\n      throw new Error('Type and value are required')\n    }\n\n    return await super.insertOne({\n      ...data,\n      key: buildSocialIdString(data as SocialKey)\n    })\n  }\n}\n\nexport class WorkspaceStatusMongoDbCollection implements DbCollection<WorkspaceStatus> {\n  constructor (private readonly wsCollection: MongoDbCollection<WorkspaceInfoWithStatus, 'uuid'>) {}\n\n  private toWsQuery (query: Query<WorkspaceStatus>): Query<WorkspaceInfoWithStatus> {\n    const res: Query<WorkspaceInfoWithStatus> = {}\n\n    for (const key of Object.keys(getFilteredQuery(query))) {\n      const qVal = (query as any)[key]\n      if (key === 'workspaceUuid') {","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/server/account/src/collections/mongo.ts#L238-L274","documentation":"SocialIdMongoDbCollection.insertOne validates that a social identity document carries both `type` and `value` before persisting. These two fields are the minimum data needed to build the composite `key` via buildSocialIdString, which uniquely identifies the social ID. If either is undefined (omitted or explicitly set to undefined), the collection refuses the insert and throws.","triggerScenarios":"Calling socialId.insertOne with a Partial<SocialId> missing `type` (e.g. { value: 'github-user-1' }), missing `value` (e.g. { type: 'github' }), or both (e.g. { personUuid: '...' } or an empty object). Explicitly passing `type: undefined` also triggers it.","commonSituations":"Building the social-ID object dynamically from optional OAuth-provider payload fields (provider name or profile id missing); a refactor that renamed `type`/`value` so the old keys no longer populate; deserializing JSON where the fields were dropped; accidentally passing a user record instead of a social-ID record.","solutions":["Ensure the object passed to insertOne contains both `type` and `value` before calling; validate at the caller/service layer.","If data comes from an external provider, check that provider name and profile identifier are present before creating the SocialId document.","Confirm you are not shadowing or renaming fields — the collection checks literal keys `type` and `value`, not alternates like `provider` or `id`.","Wrap the call in try/catch and surface a 400-style validation error to the client instead of a 500."],"exampleFix":"// before\nawait socialId.insertOne({ personUuid, value: socialValue })\n// after\nif (socialType === undefined || socialValue === undefined) {\n  throw new Error('social id type and value are required')\n}\nawait socialId.insertOne({ personUuid, type: socialType, value: socialValue })","handlingStrategy":"validation","validationCode":"function canInsertSocialId(data) {\n  return data !== null && typeof data === 'object' && data.type !== undefined && data.value !== undefined\n}\nif (!canInsertSocialId(input)) throw new Error('social id requires type and value')","typeGuard":"function isSocialIdInput(d: Partial<SocialId> | undefined | null): d is Pick<SocialId, 'type' | 'value'> & Partial<SocialId> {\n  return d !== undefined && d !== null && (d as any).type !== undefined && (d as any).value !== undefined\n}","tryCatchPattern":"try {\n  await socialId.insertOne(data)\n} catch (err) {\n  if (err instanceof Error && err.message === 'Type and value are required') {\n    throw new BadRequestError('Social ID must include type and value')\n  }\n  throw err\n}","preventionTips":["Validate `type` and `value` at the API boundary before constructing the SocialId document.","Use a typed factory function that requires both fields instead of hand-building Partial objects.","Never rename these fields locally; the collection matches literal keys `type` and `value`.","Add a unit test asserting insertOne rejects inputs missing either field."],"tags":["validation","mongodb","missing-required-field"],"backgroundTag":"missing-required-field","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}