Advertisement
Lobicky

štefan úprava

Jan 20th, 2020
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const AppClient = require("uu_appg01_server").AppClient;
  2. const { Validator } = require("uu_appg01_server").Validation;
  3. const { ValidationHelper } = require("uu_appg01_server").AppServer;
  4. const { UseCaseError } = require("uu_appg01_server").AppServer;
  5.  
  6. const { dtoIn, console, session } = scriptContext;
  7.  
  8. /*@@viewOn:dtoIn*/
  9. const dtoInSchema = `const sdeExamTask05DtoInSchemaType = shape({
  10.   classroom: array(
  11.     shape({
  12.       sex: oneOf("male","female").isRequired(),
  13.       birthdate: date().isRequired(),
  14.       name: string(),
  15.       surname: string()
  16.     }), 2000)
  17.   })`;
  18. /*@@viewOff:dtoIn*/
  19.  
  20. let person = {
  21.   name: "Lukas",
  22.   sex: "male/female"
  23. };
  24.  
  25. let {name,sex }= person
  26.  
  27. func(getName) {
  28.   let person = {
  29.     name: "Lukas",
  30.     sex: "male/female"
  31.   };
  32. }
  33.  
  34. /*@@viewOn:errors*/
  35. const Errors = {
  36.   ERROR_PREFIX: "ucl/sdeExamTask05/",
  37.  
  38.   InvalidDtoIn: class extends UseCaseError {
  39.     constructor(dtoOut, paramMap) {
  40.       super({ dtoOut, paramMap, status: 400 });
  41.       this.message = `DtoIn is not valid.`;
  42.       this.code = `${Errors.ERROR_PREFIX}invalidDtoIn`;
  43.     }
  44.   }
  45. };
  46. /*@@viewOff:errors*/
  47.  
  48. /*@@viewOn:helpers*/
  49. async function _validateDtoIn(dtoIn, uuAppErrorMap) {
  50.   //2.1.1
  51.   let dtoInValidator = new Validator(dtoInSchema, true);
  52.   //2.1.2
  53.   let validationResult = dtoInValidator.validate(
  54.     "sdeExamTask05DtoInSchemaType",
  55.     dtoIn
  56.   );
  57.   uuAppErrorMap = ValidationHelper.processValidationResult(
  58.     dtoIn,
  59.     validationResult,
  60.     `${Errors.ERROR_PREFIX}unsupportedKeys`,
  61.     Errors.InvalidDtoIn
  62.   );
  63.   //2.1.3
  64.   return uuAppErrorMap;
  65. }
  66.  
  67. function _getBirthdayCard({ name, surname, age, sex }) {
  68.   return `<UU5.Bricks.Card elevation=1 className="uu5-common-padding-m">
  69.     <UU5.Bricks.Text colorSchema="${
  70.      sex === "male" ? "blue-rich" : "pink-rich"
  71.    }" style="position: absolute;top:24px;right:24px;font-size:32px">
  72.       <UU5.Bricks.Icon icon="mdi-gift"/>
  73.     </UU5.Bricks.Text>
  74.     <UU5.Bricks.Header style="margin-top: 0" level=2>
  75.       <UU5.Bricks.Icon icon="${
  76.        sex === "male" ? "mdi-gender-male" : "mdi-gender-female"
  77.      }"/> ${name} ${surname}
  78.     </UU5.Bricks.Header>
  79.     <UU5.Bricks.Header level=4>
  80.       Dnes slaví ${age} let
  81.     </UU5.Bricks.Header>
  82.   </UU5.Bricks.Card>`;
  83. }
  84. /*@@viewOff:helpers*/
  85.  
  86. /*@@viewOn:customHelpers*/
  87.  
  88. function isBday(user) {
  89.   let actualDate = new Date();
  90.   let bday = new Date(user.birthdate);
  91.  
  92.   if (
  93.     actualDate.getDate() == bday.getDate() &&
  94.     actualDate.getMonth() == bday.getMonth()
  95.   ) {
  96.     return true;
  97.   } else {
  98.     return false;
  99.   }
  100. }
  101. /*@@viewOff:customHelpers*/
  102.  
  103. async function main() {
  104.   //1
  105.   let uuAppErrorMap = {};
  106.  
  107.   //2
  108.   await _validateDtoIn(dtoIn, uuAppErrorMap);
  109.  
  110.   /*@@viewOn:sourceCode*/
  111.  
  112.   // let birthdays = [];
  113.  
  114.   // for(let i = 0; i < dtoIn.classroom.length; i++){
  115.   //   if(isBday(dtoIn.classroom[i].birthdate)){
  116.   //     birthdays.push(dtoIn.classroom[i]);
  117.   //   }
  118.   // }
  119.   let birthdays = dtoIn.classroom.filter(isBday);
  120.  
  121.   for (let i = 0; i < birthdays.length; i++) {
  122.     console.log(_getBirthdayCard(birthdays[i]));
  123.   }
  124.  
  125.   /*@@viewOff:sourceCode*/
  126.  
  127.   return { uuAppErrorMap };
  128. }
  129.  
  130. main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement