Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(address-service): add script to create address #5699

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions apps/address-service/bin/create-address.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* Add the address manually if there is no provider
*
* Usage:
* yarn workspace @app/address-service node bin/create-address "streetName, houseNumber"
*/

const path = require('path')

const { prepareKeystoneExpressApp } = require('@open-condo/keystone/prepareKeystoneApp')

const { AddressInjection } = require('@address-service/domains/address/utils/serverSchema')

async function main(args) {
if (args.length === 0) {
throw new Error('You must provide the address in the format: "Street Name, House Number"')
}
const [streetName, houseNumber] = args[0].split(',')

if (!streetName || !houseNumber) {
throw new Error('You must provide both street name and house number in the format: "Street Name, House Number"')
}

const { keystone: context } = await prepareKeystoneExpressApp(path.resolve('./index.js'), { excludeApps: ['NextApp', 'AdminUIApp'] })

let addressData = {
country: 'Россия',
street: { 'name': streetName.trim(), 'typeFull': 'улица', 'typeShort': 'ул' },
house: { 'name': houseNumber.trim(), 'typeFull': 'дом', 'typeShort': 'д' },
dv: 1,
sender: { 'dv': 1, 'fingerprint': 'create-address-script' },
}

const address = await AddressInjection.getOne(context, { street: addressData.street, house: addressData.house })

if (!address) {
await AddressInjection.create(context, {
...addressData,
})
console.info('Address created!')
} else {
throw new Error('Address already exists')
}
}

main(process.argv.slice(2)).then(
() => {
console.info('✅ All done!')
process.exit()
},
(error) => {
console.error(error)
process.exit(1)
},
)