auto commit
This commit is contained in:
parent
613a626613
commit
9de2286eff
@ -81,6 +81,18 @@ class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async edgeLogin(username, password, businessNumber, ipAddress, userAgent) {
|
async edgeLogin(username, password, businessNumber, ipAddress, userAgent) {
|
||||||
|
try {
|
||||||
|
// businessNumber를 숫자로 변환
|
||||||
|
const numericBusinessNumber = parseInt(
|
||||||
|
businessNumber.replace(/[-,]/g, ""),
|
||||||
|
10
|
||||||
|
);
|
||||||
|
|
||||||
|
logger.debug("Converted business number:", {
|
||||||
|
original: businessNumber,
|
||||||
|
numeric: numericBusinessNumber,
|
||||||
|
});
|
||||||
|
|
||||||
// 1. 먼저 회사 검증
|
// 1. 먼저 회사 검증
|
||||||
const company = await Company.findOne({
|
const company = await Company.findOne({
|
||||||
where: {
|
where: {
|
||||||
@ -154,7 +166,10 @@ class AuthService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 5. 마지막 로그인 시간 업데이트
|
// 5. 마지막 로그인 시간 업데이트
|
||||||
await User.update({ lastLoginAt: new Date() }, { where: { id: user.id } });
|
await User.update(
|
||||||
|
{ lastLoginAt: new Date() },
|
||||||
|
{ where: { id: user.id } }
|
||||||
|
);
|
||||||
|
|
||||||
// 6. 로그인 기록
|
// 6. 로그인 기록
|
||||||
await this._logAuthAttempt(
|
await this._logAuthAttempt(
|
||||||
@ -188,6 +203,14 @@ class AuthService {
|
|||||||
token,
|
token,
|
||||||
user: userInfo,
|
user: userInfo,
|
||||||
};
|
};
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Edge login error:", {
|
||||||
|
error: error.message,
|
||||||
|
businessNumber,
|
||||||
|
username,
|
||||||
|
});
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_processPermissions(roles) {
|
_processPermissions(roles) {
|
||||||
|
@ -9,41 +9,58 @@ const {
|
|||||||
const { createInitialData } = require("./initialSetup/dataSetup");
|
const { createInitialData } = require("./initialSetup/dataSetup");
|
||||||
const { logCreatedAccounts } = require("./initialSetup/loggingSetup");
|
const { logCreatedAccounts } = require("./initialSetup/loggingSetup");
|
||||||
|
|
||||||
|
// 상수로 정의하여 일관성 유지
|
||||||
|
const ADMIN_COMPANY = {
|
||||||
|
BUSINESS_NUMBER: 4397802852, // 올바른 번호로 수정
|
||||||
|
NAME: "FEMS 관리자",
|
||||||
|
ADDRESS: "서울시 강남구",
|
||||||
|
TEL: "02-0000-0000",
|
||||||
|
EMAIL: "admin@fems.com",
|
||||||
|
REPRESENTATIVE: "관리자",
|
||||||
|
};
|
||||||
|
|
||||||
async function createInitialAdmin() {
|
async function createInitialAdmin() {
|
||||||
try {
|
try {
|
||||||
// 1. 관리자 회사 생성 또는 조회
|
// 사업자번호로 회사 조회
|
||||||
let adminCompany = await Company.findOne({
|
let adminCompany = await Company.findOne({
|
||||||
where: { businessNumber: 4398702852 },
|
where: { businessNumber: ADMIN_COMPANY.BUSINESS_NUMBER },
|
||||||
});
|
});
|
||||||
|
|
||||||
let adminBranch; // Branch 변수 선언
|
let adminBranch; // Branch 변수 선언
|
||||||
const businessNumber = parseInt("439-78-02852".replace(/-/g, ""), 10);
|
|
||||||
|
|
||||||
if (!adminCompany) {
|
if (!adminCompany) {
|
||||||
|
// 회사 생성
|
||||||
adminCompany = await Company.create({
|
adminCompany = await Company.create({
|
||||||
name: "FEMS 관리자",
|
name: ADMIN_COMPANY.NAME,
|
||||||
businessNumber,
|
businessNumber: ADMIN_COMPANY.BUSINESS_NUMBER, // 상수 사용
|
||||||
address: "서울시 강남구",
|
address: ADMIN_COMPANY.ADDRESS,
|
||||||
tel: "02-0000-0000",
|
tel: ADMIN_COMPANY.TEL,
|
||||||
email: "admin@fems.com",
|
email: ADMIN_COMPANY.EMAIL,
|
||||||
representative: "관리자",
|
representative: ADMIN_COMPANY.REPRESENTATIVE,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
contractStartDate: new Date(),
|
contractStartDate: new Date(),
|
||||||
contractEndDate: new Date(
|
contractEndDate: new Date(
|
||||||
new Date().setFullYear(new Date().getFullYear() + 10)
|
new Date().setFullYear(new Date().getFullYear() + 10)
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
logger.info("Admin company created successfully");
|
|
||||||
|
logger.info("Admin company created successfully", {
|
||||||
|
companyId: adminCompany.id,
|
||||||
|
businessNumber: ADMIN_COMPANY.BUSINESS_NUMBER,
|
||||||
|
});
|
||||||
|
|
||||||
// 본사 지점 생성
|
// 본사 지점 생성
|
||||||
adminBranch = await Branch.create({
|
adminBranch = await Branch.create({
|
||||||
name: "본사",
|
name: "본사",
|
||||||
address: "서울시 강남구",
|
address: ADMIN_COMPANY.ADDRESS,
|
||||||
tel: "02-0000-0000",
|
tel: ADMIN_COMPANY.TEL,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
companyId: adminCompany.id,
|
companyId: adminCompany.id,
|
||||||
});
|
});
|
||||||
logger.info("Admin company headquarters branch created successfully");
|
|
||||||
|
logger.info("Admin branch created successfully", {
|
||||||
|
branchId: adminBranch.id,
|
||||||
|
companyId: adminCompany.id,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
// 기존 회사의 지점 조회
|
// 기존 회사의 지점 조회
|
||||||
adminBranch = await Branch.findOne({
|
adminBranch = await Branch.findOne({
|
||||||
|
Loading…
Reference in New Issue
Block a user