Commit 402aad11 authored by Ermolaev Timur's avatar Ermolaev Timur

#17 Реализовал юзеров в фикстуре

parent d1b8f15f
This diff is collapsed.
...@@ -7,18 +7,21 @@ ...@@ -7,18 +7,21 @@
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon", "dev": "nodemon",
"start": "npm run build && node build/server.js", "start": "npm run build && node build/server.js",
"lint": "eslint . --ext .ts" "lint": "eslint . --ext .ts",
"fixtures": "ts-node ./src/fixtures.ts"
}, },
"keywords": [], "keywords": [],
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"@faker-js/faker": "^7.6.0",
"@types/node": "^18.11.8", "@types/node": "^18.11.8",
"@typescript-eslint/eslint-plugin": "^5.41.0", "@typescript-eslint/eslint-plugin": "^5.41.0",
"@typescript-eslint/parser": "^5.41.0", "@typescript-eslint/parser": "^5.41.0",
"eslint": "^8.26.0", "eslint": "^8.26.0",
"nodemon": "^2.0.20", "nodemon": "^2.0.20",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",
"typeorm-fixtures-cli": "^3.0.1",
"typescript": "^4.8.4" "typescript": "^4.8.4"
}, },
"dependencies": { "dependencies": {
......
import { myDataSource } from "./app-data-source";
import { User, UserRole } from "./models/User";
import { faker } from '@faker-js/faker';
import { Task } from "./models/Task";
function randomIntFromInterval(min:number, max:number) {
return Math.floor(Math.random() * (max - min + 1) + min)
}
const loadFixtures = async () => {
myDataSource
.initialize()
.then(async () => {
console.log(`
==========================
Data Source has been initialized!
==========================
`)
const userRoles = [{role: UserRole.DIRECTOR}, {role: UserRole.SUPERUSER}, {role: UserRole.USER}, {role: UserRole.USER}];
const users = []
for (let i = 0; i < 4; i++) {
const name = faker.name.firstName()
const surname = faker.name.lastName()
const displayName = name + ' ' + surname[0] + '.'
const user = new User()
user.name = name;
user.surname = surname;
user.password = '12345qwert';
user.displayName= displayName;
user.phone = faker.phone.number('+77#########')
user.email = faker.internet.email();
user.role = userRoles[i].role;
user.generateToken()
await user.save();
users.push(user)
}
})
.catch((err) => {
console.error("Error during Data Source initialization:", err)
})
};
loadFixtures()
\ No newline at end of file
...@@ -11,7 +11,7 @@ import { ...@@ -11,7 +11,7 @@ import {
import {User} from './User'; import {User} from './User';
import {Project} from './Project'; import {Project} from './Project';
type taskFinishType = "open" | "done" |"failed"; type taskFinishType = "opened" | "done" |"failed";
type priorityType = "A" | "B" |"C"; type priorityType = "A" | "B" |"C";
interface ITask{ interface ITask{
......
...@@ -43,20 +43,20 @@ interface IUser { ...@@ -43,20 +43,20 @@ interface IUser {
export class User extends BaseEntity implements IUser { export class User extends BaseEntity implements IUser {
@PrimaryGeneratedColumn("uuid") @PrimaryGeneratedColumn("uuid")
id!: string; id!: string;
@Column({ name: 'name', type: 'varchar', length:20,nullable: false }) @Column({ name: 'name', type: 'varchar', length:30,nullable: false })
name!: string; name!: string;
@Column({ name: 'surname', type: 'varchar', length:30,nullable: false }) @Column({ name: 'surname', type: 'varchar', length:30,nullable: false })
surname!: string; surname!: string;
@Column({ name: 'displayName', type: 'varchar', length:30,nullable: false }) @Column({ name: 'displayName', type: 'varchar', length:35,nullable: false })
displayName!: string; displayName!: string;
@Column({ name: 'email', type: 'varchar',length:20, unique: true, nullable: false }) @Column({ name: 'email', type: 'varchar',length:40, unique: true, nullable: false })
@IsEmail() @IsEmail()
email!: string; email!: string;
@Column({ name: 'phone', type: 'varchar',length:10, unique: true, nullable: true}) @Column({ name: 'phone', type: 'varchar',length:15, unique: true, nullable: true})
phone?: string; phone?: string;
@Column({ name: 'token', type: 'varchar',length:100, unique: true, nullable: false }) @Column({ name: 'token', type: 'varchar',length:100, unique: true, nullable: false })
......
...@@ -44,7 +44,7 @@ export const addTask = (task) => { ...@@ -44,7 +44,7 @@ export const addTask = (task) => {
try { try {
await axios.post("/tasks", task, { await axios.post("/tasks", task, {
headers: { headers: {
'Authorization': 'aBhHYW8kXUUzjXlxOwGmg' 'Authorization': 'yjBjcPCQwytwrYo9rRuiK'
} }
}); });
dispatch(addTaskSuccess()) dispatch(addTaskSuccess())
......
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