Skip to content

Commit c6b9b3e

Browse files
committed
forgot-password, changed-password, update-file-spbb
1 parent 035f6d7 commit c6b9b3e

27 files changed

+426
-18
lines changed

.env.example

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,8 @@ PATH_URL=
3030
NODE_ENV=
3131
X_API_KEY=
3232
URL_FILE=
33-
DIRECTORY_FILE=
33+
DIRECTORY_FILE=
34+
35+
#email
36+
EMAIL_HOST=
37+
EMAIL_PORT=

package-lock.json

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"fastify-multer": "^2.0.3",
4747
"mysql": "^2.18.1",
4848
"mysql2": "^2.3.3",
49+
"nodemailer": "^6.9.2",
4950
"pino": "^8.7.0",
5051
"redis": "^4.6.5",
5152
"trash-cli": "^5.0.0",

src/app.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ import {
6262
UpdatePkhoaUseCase,
6363
UpdatePksCurahUseCase,
6464
GetPkhoaExcludeUseCase,
65-
DeletePengajuanKontrakPksUseCase
65+
DeletePengajuanKontrakPksUseCase,
66+
ChangedPasswordPurchasingUseCase,
67+
ForgotPasswordPurchasingUseCase
6668
} from './domain'
6769
import cluster from 'cluster'
6870
import os from 'os'
@@ -124,6 +126,14 @@ const app = async () => {
124126
new LoginUserPurchasingUseCase(
125127
new PurchasingRepository(new UsersDataSource(sourcesDml, sourcesDql), new PksCurahDataSource(sourcesDml, sourcesDql), new FreightDataSource(sourcesDml, sourcesDql), new HistoryLogDataSource(sourcesDml, sourcesDql), new CurrencyDataSource(sourcesDml, sourcesDql), new StockpileDataSource(sourcesDml, sourcesDql), new PkhoaDataSource(sourcesDml, sourcesDql), new PurchasingDataSource(sourcesDml, sourcesDql), new PoPksDataSource(sourcesDml, sourcesDql), new VendorKontrakDataSource(sourcesDml, sourcesDql), new SetupsDataSource(sourcesDml, sourcesDql), new PurchasingFreightCostDataSource(sourcesDml, sourcesDql))
126128
),
129+
new ChangedPasswordPurchasingUseCase(
130+
new PurchasingRepository(new UsersDataSource(sourcesDml, sourcesDql), new PksCurahDataSource(sourcesDml, sourcesDql), new FreightDataSource(sourcesDml, sourcesDql), new HistoryLogDataSource(sourcesDml, sourcesDql), new CurrencyDataSource(sourcesDml, sourcesDql), new StockpileDataSource(sourcesDml, sourcesDql), new PkhoaDataSource(sourcesDml, sourcesDql), new PurchasingDataSource(sourcesDml, sourcesDql), new PoPksDataSource(sourcesDml, sourcesDql), new VendorKontrakDataSource(sourcesDml, sourcesDql), new SetupsDataSource(sourcesDml, sourcesDql), new PurchasingFreightCostDataSource(sourcesDml, sourcesDql)),
131+
new UsersDataSource(sourcesDml, sourcesDql)
132+
),
133+
new ForgotPasswordPurchasingUseCase(
134+
new PurchasingRepository(new UsersDataSource(sourcesDml, sourcesDql), new PksCurahDataSource(sourcesDml, sourcesDql), new FreightDataSource(sourcesDml, sourcesDql), new HistoryLogDataSource(sourcesDml, sourcesDql), new CurrencyDataSource(sourcesDml, sourcesDql), new StockpileDataSource(sourcesDml, sourcesDql), new PkhoaDataSource(sourcesDml, sourcesDql), new PurchasingDataSource(sourcesDml, sourcesDql), new PoPksDataSource(sourcesDml, sourcesDql), new VendorKontrakDataSource(sourcesDml, sourcesDql), new SetupsDataSource(sourcesDml, sourcesDql), new PurchasingFreightCostDataSource(sourcesDml, sourcesDql)),
135+
new UsersDataSource(sourcesDml, sourcesDql)
136+
),
127137
new PengajuanPksCurahUseCase(
128138
new PurchasingRepository(new UsersDataSource(sourcesDml, sourcesDql), new PksCurahDataSource(sourcesDml, sourcesDql), new FreightDataSource(sourcesDml, sourcesDql), new HistoryLogDataSource(sourcesDml, sourcesDql), new CurrencyDataSource(sourcesDml, sourcesDql), new StockpileDataSource(sourcesDml, sourcesDql), new PkhoaDataSource(sourcesDml, sourcesDql), new PurchasingDataSource(sourcesDml, sourcesDql), new PoPksDataSource(sourcesDml, sourcesDql), new VendorKontrakDataSource(sourcesDml, sourcesDql), new SetupsDataSource(sourcesDml, sourcesDql), new PurchasingFreightCostDataSource(sourcesDml, sourcesDql))
129139
),

src/data/data-sources/purchasing/purchasing-data-source.ts

+36-4
Original file line numberDiff line numberDiff line change
@@ -37,33 +37,55 @@ export class PurchasingDataSource implements IPurchasingDataSource {
3737
throw new Error("Method not implemented.");
3838
}
3939

40-
async selectAll(conf: Pick<ParamsEntity, 'limit' | 'offset' | 'search' | 'kontrak_type' | 'pks_type' | 'stockpile_id'>): Promise<PurchasingEntity[]> {
40+
async selectAll(conf: Pick<ParamsEntity, 'limit' | 'offset' | 'search' | 'kontrak_type' | 'pks_type' | 'stockpile_id' | 'final_status'>): Promise<PurchasingEntity[]> {
4141
let limit = ''
4242
let where = ``
43+
let orderBy = `, p.purchasing_id DESC`
4344

4445
if (conf!.pks_type == 'PKS-Contract') {
4546
where = `where p.type = 1 and p.contract_type = 1`
4647
if (conf!.stockpile_id) {
4748
where += ` and s.stockpile_id = ${conf!.stockpile_id}`
4849
}
4950
if (conf!.search) where += ` and (v.vendor_name LIKE '%${conf!.search}%' or s.stockpile_name LIKE '%${conf!.search}%')`
51+
if (conf!.final_status) {
52+
where += ` and popks.final_status = ${conf?.final_status}`
53+
orderBy = conf!.final_status == 2 || conf!.final_status == 3 ? `, p.purchasing_id ASC` : `, p.purchasing_id DESC`
54+
}
5055
} else if (conf!.pks_type == 'PKS-Curah') {
5156
where = `where p.type = 2 and p.contract_type = 1`
5257
if (conf!.stockpile_id) {
5358
where += ` and s.stockpile_id = ${conf!.stockpile_id}`
5459
}
5560
if (conf!.search) where += ` and (v.vendor_name LIKE '%${conf!.search}%' or s.stockpile_name LIKE '%${conf!.search}%')`
61+
if (conf!.final_status) {
62+
where += ` and popks.final_status = ${conf?.final_status}`
63+
orderBy = conf!.final_status == 2 || conf!.final_status == 3 ? `, p.purchasing_id ASC` : `, p.purchasing_id DESC`
64+
}
5665
} else if (conf!.kontrak_type == 'PKS-Spb') {
5766
where = `where (p.type = 2 or p.type = 1) and p.contract_type = 2`
5867
if (conf!.stockpile_id) {
5968
where += ` and s.stockpile_id = ${conf!.stockpile_id}`
6069
}
6170
if (conf!.search) where += ` and (v.vendor_name LIKE '%${conf!.search}%' or s.stockpile_name LIKE '%${conf!.search}%')`
71+
if (conf!.final_status) {
72+
where += ` and popks.final_status = ${conf?.final_status}`
73+
orderBy = conf!.final_status == 2 || conf!.final_status == 3 ? `, p.purchasing_id ASC` : `, p.purchasing_id DESC`
74+
}
6275
} else if (conf!.stockpile_id) {
6376
where = `where s.stockpile_id = ${conf!.stockpile_id}`
6477
if (conf!.search) where += ` and (v.vendor_name LIKE '%${conf!.search}%' or s.stockpile_name LIKE '%${conf!.search}%')`
65-
} else if (conf!.search) where = `where (v.vendor_name LIKE '%${conf!.search}%' or s.stockpile_name LIKE '%${conf!.search}%')`
66-
78+
if (conf!.final_status) {
79+
where += ` and popks.final_status = ${conf?.final_status}`
80+
orderBy = conf!.final_status == 2 || conf!.final_status == 3 ? `, p.purchasing_id ASC` : `, p.purchasing_id DESC`
81+
}
82+
} else if (conf!.search) {
83+
where = `where (v.vendor_name LIKE '%${conf!.search}%' or s.stockpile_name LIKE '%${conf!.search}%')`
84+
if (conf!.final_status) {
85+
where += ` and popks.final_status = ${conf?.final_status}`
86+
orderBy = conf!.final_status == 2 || conf!.final_status == 3 ? `, p.purchasing_id ASC` : `, p.purchasing_id DESC`
87+
}
88+
}
6789
if (conf!.offset || conf.limit) limit = `limit ${conf.offset}, ${conf.limit}`
6890

6991
const [rows, fields] = await this.dql.dataQueryLanguage(
@@ -104,7 +126,7 @@ export class PurchasingDataSource implements IPurchasingDataSource {
104126
LEFT JOIN ${process.env.TABLE_POPKS} popks
105127
ON popks.purchasing_id = p.purchasing_id
106128
${where}
107-
ORDER BY popks.final_status DESC, p.purchasing_id DESC
129+
ORDER BY popks.final_status DESC ${orderBy}
108130
${limit};
109131
`, []
110132
)
@@ -186,6 +208,16 @@ export class PurchasingDataSource implements IPurchasingDataSource {
186208
return res
187209
}
188210

211+
async updateFileSpb(id?: number | undefined, data?: Pick<PurchasingEntity, "import2" | "approval_file" | "upload_file1" | "upload_file2" | "upload_file3" | "upload_file4" | "import2_date"> | undefined): Promise<any> {
212+
const res = await this.dml.dataManipulation(
213+
`update file purchasing, spb`,
214+
`update ${process.env.TABLE_PURCHASING} set import2 = ?, approval_file = ?, upload_file1 = ?, upload_file2 = ?, upload_file3 = ?, upload_file4 = ?, import2_date = ? where purchasing_id = ? and status = ?`,
215+
[data?.import2, data?.approval_file, data?.upload_file1, data?.upload_file2, data?.upload_file3, data?.upload_file4, data?.import2_date, id!, 2]
216+
)
217+
218+
return res
219+
}
220+
189221
async delete(id?: number | undefined): Promise<any> {
190222
const res = await this.dml.dataManipulation(
191223
`delete purchasing`,

src/data/data-sources/users/user-data-sources.ts

+10
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,14 @@ export class UsersDataSource implements IUsersDataSource {
6262

6363
return rows[0]
6464
}
65+
66+
async updateKodeAksesUserPurchasing(deviced_id: string, kode_akses: string): Promise<any> {
67+
const res = await this.dml.dataManipulation(
68+
'update kode akses user purchasing',
69+
`update ${process.env.TABLE_USER_PURCHASING} set kode_akses = ? where deviced_id = ?`,
70+
[kode_akses, deviced_id]
71+
)
72+
73+
return res
74+
}
6575
}

src/data/interfaces/purchasing/interface-kontrak-pks-data-source.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ export interface IPurchasingDataSource {
44
count(): Promise<any>
55
insert(data?: PurchasingEntity): Promise<any>
66
update(id?: number, data?: PurchasingEntity): Promise<any>
7-
selectAll(conf: Pick<ParamsEntity, 'limit' | 'offset' | 'search' | 'kontrak_type' | 'pks_type' | 'stockpile_id'>): Promise<PurchasingEntity[]>
7+
selectAll(conf: Pick<ParamsEntity, 'limit' | 'offset' | 'search' | 'kontrak_type' | 'pks_type' | 'stockpile_id' | 'final_status'>): Promise<PurchasingEntity[]>
88
selectOne(id?: number): Promise<PurchasingEntity | null>
99
selectOneDynamic(conf?: Pick<ParamsEntity, 'columnKey' | 'columnValue'>): Promise<PurchasingEntity[]>
1010
selectPlanPaymentDate(): Promise<any>
1111
delete(id?: number): Promise<any>
1212
updateFile(id?: number, data?: Pick<PurchasingEntity, 'upload_file' | 'approval_file' | 'upload_file1' | 'upload_file2' | 'upload_file3' | 'upload_file4'>): Promise<any>
13+
updateFileSpb(id?: number, data?: Pick<PurchasingEntity, 'import2' | 'approval_file' | 'upload_file1' | 'upload_file2' | 'upload_file3' | 'upload_file4' | 'import2_date'>): Promise<any>
1314
selectWhereDynamic(conf?: Pick<ParamsEntity, 'whereKey' | 'whereValue'>): Promise<PurchasingEntity | null>
1415
}
1516

src/data/interfaces/users/interface-user-data-source.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export interface IUsersDataSource {
44
registerUserPurchasing(data: EntityUser): Promise<any>
55
selectByEmail(email: string): Promise<EntityUser | null>
66
selectByDeviceId(deviceId: string): Promise<EntityUser | null>
7+
updateKodeAksesUserPurchasing(deviced_id: string, kode_akses: string): Promise<any>
78
}

src/data/middlewares/multer.ts

+6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ export const storageMulterFastify = multerFastify.diskStorage({
6060
`${revisi}${Date.now()}-` + `${Math.floor(Math.random() * 10)}` +
6161
`${path.extname(file.originalname)}`
6262
}
63+
if (req.files['import2']) {
64+
nameFile = `import2-${req.body.stockpile_id}-${req.body.vendor_id}-${req.body.contract_type}-${req.body.type}` +
65+
'-' +
66+
`${revisi}${Date.now()}-` + `${Math.floor(Math.random() * 10)}` +
67+
`${path.extname(file.originalname)}`
68+
}
6369
if (req.files['approval_file']) {
6470
nameFile = `approval_file-${req.body.stockpile_id}-${req.body.vendor_id}-${req.body.contract_type}-${req.body.type}` +
6571
'-' +

src/domain/entity/api/email-entity.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export interface OptionsEmail {
2+
from?: string,
3+
to?: string,
4+
subject?: string
5+
html?: string
6+
}
7+
8+
export interface TransporterAuth {
9+
user?: string
10+
pass?: string
11+
}
12+
13+
export interface TranspoterOptions {
14+
host?: string
15+
port?: number
16+
auth?: TransporterAuth
17+
}

src/domain/entity/api/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './headers-entity'
22
export * from './params-entity'
33
export * from './response-entity'
4-
export * from './pagination-entity'
4+
export * from './pagination-entity'
5+
export * from './email-entity'

src/domain/entity/api/params-entity.ts

+2
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ export interface ParamsEntity {
1919
pks_type?: string | number
2020
purchasing_id?: number
2121
re_entry?: boolean
22+
final_status?: number
23+
status?: number
2224
}

src/domain/interfaces/repository/interface-purchasing-repo.ts

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface IPurchasingRepo {
1717
registerUserPurchasing(data: EntityUser): Promise<any>
1818
checkEmail(email: string): Promise<EntityUser | null>
1919
checkDeviceId(deviceId: string): Promise<EntityUser | null>
20+
updateKodeAksesUser(deviced_id: string, kode_akses: string): Promise<any>
2021
pengajuanPksCurah(user_id?: number, data?: PksCurahEntity): Promise<any>
2122
pengajuanFreight(user_id?: number, data?: FreightEntity): Promise<any>
2223
findAllPksCurah(
@@ -75,4 +76,5 @@ export interface IPurchasingRepo {
7576
deleteVendorKontrak(id?: number, user_id?: number): Promise<any>
7677
deletePurchasingFreightCost(id?: number, user_id?: number): Promise<any>
7778
updateFilePurchasing(id?: number, user_id?: number, data?: Pick<PurchasingEntity, 'upload_file' | 'approval_file' | 'upload_file1' | 'upload_file2' | 'upload_file3' | 'upload_file4'>): Promise<any>
79+
updateFileSpbPurchasing(id?: number, user_id?: number, data?: Pick<PurchasingEntity, 'import2' | 'approval_file' | 'upload_file1' | 'upload_file2' | 'upload_file3' | 'upload_file4' | 'import2_date'>): Promise<any>
7880
}

src/domain/interfaces/use-cases/interface-purchasing-use-case.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ export interface ILoginUserPurchasingUseCase {
88
execute(data: EntityUser): Promise<EntityUser | null>
99
}
1010

11+
export interface IChangedPasswordPurchasingUseCase {
12+
execute(deviced_id?: string, current_password?: string, new_password?: string): Promise<any>
13+
}
14+
15+
export interface IForgotPasswordPurchasingUseCase {
16+
execute(deviced_id?: string, email?: string): Promise<any>
17+
}
18+
1119
export interface IPengajuanPksCurahUseCase {
1220
execute(user_id?: number, data?: PksCurahEntity): Promise<any>
1321
}
@@ -125,5 +133,5 @@ export interface IDeletePengajuanKontrakPksUseCase {
125133
}
126134

127135
export interface IUpdateFilePurchasingUseCase {
128-
execute(id?: number, user_id?: number, data?: Pick<PurchasingEntity, 'upload_file' | 'approval_file' | 'upload_file1' | 'upload_file2' | 'upload_file3' | 'upload_file4'>): Promise<any>
136+
execute(id?: number, user_id?: number, status?: number, final_status?: number, data?: Pick<PurchasingEntity, 'upload_file' | 'import2' | 'import2_date' | 'approval_file' | 'upload_file1' | 'upload_file2' | 'upload_file3' | 'upload_file4'>): Promise<any>
129137
}

src/domain/repository/purchasing/index.ts

+22
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ export class PurchasingRepository implements IPurchasingRepo {
4747
return res
4848
}
4949

50+
async updateKodeAksesUser(deviced_id: string, kode_akses: string): Promise<any> {
51+
const res = await this.userDataSource.updateKodeAksesUserPurchasing(deviced_id, kode_akses)
52+
return res
53+
}
54+
5055
async pengajuanPksCurah(user_id?: number, data?: PksCurahEntity | undefined): Promise<any> {
5156
const res = await this.pksCurahDataSource.insert(data)
5257

@@ -579,4 +584,21 @@ export class PurchasingRepository implements IPurchasingRepo {
579584
return res
580585
}
581586

587+
async updateFileSpbPurchasing(id?: number | undefined, user_id?: number | undefined, data?: Pick<PurchasingEntity, 'import2' | 'approval_file' | 'upload_file1' | 'upload_file2' | 'upload_file3' | 'upload_file4' | 'import2_date'> | undefined): Promise<any> {
588+
data!.import2_date = `${format(new Date(), 'yyyy-MM-dd HH:mm:ss')}`
589+
const res = await this.purchasingDataSource.updateFileSpb(id, data)
590+
591+
const dataHistoryLog: HistoryLogEntity = {
592+
tanggal: `${format(new Date(), 'yyyy-MM-dd HH:mm:ss')}`,
593+
transaksi: `${id}`,
594+
cud: 'UPDATE',
595+
isitransaksi_lama: `MENGUBAH KONTRAK PKS FILE SPB PURCHASING YANG DIAJUKAN`,
596+
user_id: user_id
597+
}
598+
599+
await this.historyLogDataSource.insert(dataHistoryLog)
600+
601+
return res
602+
}
603+
582604
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { AppError } from "@jpj-common/module";
2+
import { IChangedPasswordPurchasingUseCase, IPurchasingRepo } from "../../interfaces";
3+
import { IUsersDataSource } from "../../../data";
4+
import bcryptjs from 'bcryptjs'
5+
6+
export class ChangedPasswordPurchasingUseCase implements IChangedPasswordPurchasingUseCase {
7+
private purchasingRepo: IPurchasingRepo
8+
private userDataSource: IUsersDataSource
9+
10+
constructor(purchasingRepo: IPurchasingRepo, userDataSource: IUsersDataSource) {
11+
this.purchasingRepo = purchasingRepo
12+
this.userDataSource = userDataSource
13+
}
14+
15+
async execute(deviced_id?: string, current_password?: string, new_password?: string | undefined): Promise<any> {
16+
try {
17+
let checkDevicedId = await this.userDataSource.selectByDeviceId(deviced_id!);
18+
let comparePassword = await bcryptjs.compare(
19+
`${current_password!}`,
20+
`${checkDevicedId?.kode_akses!}`
21+
)
22+
23+
if (checkDevicedId == null || !checkDevicedId) {
24+
return { checkDevicedId: true }
25+
}
26+
27+
if (!comparePassword) {
28+
return { checkComparePassword: true }
29+
}
30+
31+
let saltPass = await bcryptjs.genSalt(5)
32+
let hashPass = await bcryptjs.hash(new_password!, saltPass)
33+
const res = await this.purchasingRepo.updateKodeAksesUser(deviced_id!, hashPass!)
34+
35+
return { updatedPassword: res }
36+
} catch (error) {
37+
throw new AppError(500, false, `${error}`, '5001')
38+
}
39+
}
40+
}

src/domain/use-cases/purchasing/findall-kontrak-pks.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export class GetAllKontrakPksUseCase implements IGetAllKontrakPksUseCase {
2121
search: conf?.search,
2222
pks_type: conf?.pks_type,
2323
kontrak_type: conf?.kontrak_type,
24-
stockpile_id: conf?.stockpile_id
24+
stockpile_id: conf?.stockpile_id,
25+
final_status: conf?.final_status
2526
}
2627
limitNumber = limit
2728
}

0 commit comments

Comments
 (0)