import LoginToken, { ILoginToken } from "../../../models/login_token";
import moment = require("moment");

export async function upgradeToken(token: ILoginToken) {
   token.data = undefined;
   token.valid = true;
   token.validated = true;
   //TODO durations from config
   let expires = (token.special
      ? moment().add(30, "minute")
      : moment().add(6, "months")
   ).toDate();
   token.validTill = expires;
   await LoginToken.save(token);
   return expires;
}
