Skip to content

Change birthdate field to age field #936

@allennatang

Description

@allennatang

Overview

Change hacker account's birthdate field to age field. Currently, there is a function to calculate age from birthdate (updates automatically?), I will comment this out. Does changing this in hackerAPI change it in the database as well?

Same change as dashboard issue #1003

Technical details

  • Change type from "String" to "Number" in hackerAPI\docs\api\api_data.js
  • Create function ageValidator() in hackerAPI\middlewares\validators\validator.helper.js to validate that age is between 0 and 100
  • Comment out getAge function in hackerAPI\models\account.model.js
AccountSchema.methods.getAge = function() {
     // birthday is a date
     var ageDifMs = Date.now() - this.birthDate.getTime();
     var ageDate = new Date(ageDifMs); // miliseconds from epoch
     return Math.abs(ageDate.getUTCFullYear() - 1970);
};

used in hackerAPI\services\hacker.service.js

const age = hacker.accountId.getAge();
stats.age[age] = stats.age[age] ? stats.age[age] + 1 : 1;

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions