#69 fix fixtures

parent 296994dc
...@@ -8,11 +8,12 @@ import { Member, MemberRole } from "./models/Member"; ...@@ -8,11 +8,12 @@ import { Member, MemberRole } from "./models/Member";
import { DateTimeTask } from "./models/DateTimeTask"; import { DateTimeTask } from "./models/DateTimeTask";
function randomIntFromInterval(min:number, max:number) { function randomIntFromInterval(min:number, max:number) {
return Math.floor(Math.random() * (max - min + 1) + min) min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min);
} }
let countUsers = 0
let countMembers =0 let countMembers =0
let countProjects = 0
let countRolesProject=0 let countRolesProject=0
const cycleThroughObject=(countKey:number,objectObserve:any):MemberRole=>{ const cycleThroughObject=(countKey:number,objectObserve:any):MemberRole=>{
...@@ -35,15 +36,6 @@ const cycleArrayOfMembers=(countIndex:number, members:Member[]):Member=>{ ...@@ -35,15 +36,6 @@ const cycleArrayOfMembers=(countIndex:number, members:Member[]):Member=>{
} }
const cycleArrayOfProjects=(countIndex:number, projects:Project[]):Project=>{
let project = projects[countIndex]
countIndex++
if (countIndex ===projects.length-1){
countIndex=0
}
return project
}
const loadFixtures = async () => { const loadFixtures = async () => {
myDataSource myDataSource
.initialize() .initialize()
...@@ -86,16 +78,16 @@ const loadFixtures = async () => { ...@@ -86,16 +78,16 @@ const loadFixtures = async () => {
for (let i = 0; i < 20; i++) { for (let i = 0; i < 20; i++) {
let dateOfMonth = randomIntFromInterval(20, 30) let dateOfMonth = randomIntFromInterval(20, 30)
let deadLineDateOfMonth = randomIntFromInterval(1, 15) let deadLineDateOfMonth = randomIntFromInterval(1, 10)
let startDateTime = new Date(2022, 11, dateOfMonth, randomIntFromInterval(10, 15), 0, 0); let startDateTime = new Date(2022, 10, dateOfMonth, randomIntFromInterval(16, 21), 0, 0);
let dueDateTime = new Date(2022, 11, dateOfMonth, randomIntFromInterval(16, 20), 0, 0); let dueDateTime = new Date(2022, 10, dateOfMonth, randomIntFromInterval(22, 22), 0, 0);
let deadLine = new Date(2022, 12, deadLineDateOfMonth, 0, 0, 0); let deadLine = new Date(2022, 11, deadLineDateOfMonth, 0, 0, 0);
const newDateTimeTask= new DateTimeTask() const newDateTimeTask= new DateTimeTask()
newDateTimeTask.dateTimeStart=startDateTime; newDateTimeTask.dateTimeStart=startDateTime;
newDateTimeTask.dateTimeDue=dueDateTime; newDateTimeTask.dateTimeDue=dueDateTime;
await newDateTimeTask.save() await newDateTimeTask.save()
if (i <= 15) { if (i <= 15) {
const newTask = new Task(); const newTask = new Task();
newTask.title = `Buy ${faker.commerce.productName()}`; newTask.title = `Buy ${faker.commerce.productName()}`;
newTask.description = faker.random.words(4); newTask.description = faker.random.words(4);
newTask.author = faker.helpers.arrayElement(users); newTask.author = faker.helpers.arrayElement(users);
......
...@@ -31,7 +31,7 @@ router.get('/my',auth, async (req:Request, res:Response): Promise<Response>=> { ...@@ -31,7 +31,7 @@ router.get('/my',auth, async (req:Request, res:Response): Promise<Response>=> {
if (rawProjects.length>0){ if (rawProjects.length>0){
for(let project of rawProjects){ for(let project of rawProjects){
projectIds.push(project.id projectIds.push(project.id
) )
} }
} }
const projects = await dataSource const projects = await dataSource
......
...@@ -33,7 +33,7 @@ const users = await dataSource ...@@ -33,7 +33,7 @@ const users = await dataSource
.createQueryBuilder("user") .createQueryBuilder("user")
.getMany() .getMany()
return res.send({users}) return res.send({users})
}) })
/**create new user*/ /**create new user*/
router.post('/', upload.single("avatar"), async (req : Request, res : Response):Promise<object> => { router.post('/', upload.single("avatar"), async (req : Request, res : Response):Promise<object> => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment