mirror of
https://github.com/sasjs/server.git
synced 2025-12-10 19:34:34 +00:00
23 lines
536 B
TypeScript
23 lines
536 B
TypeScript
import Client from '../model/Client'
|
|
|
|
export const createClient = async (data: any) => {
|
|
const { clientid, clientsecret } = data
|
|
|
|
// Checking if client is already in the database
|
|
const clientExist = await Client.findOne({ clientid })
|
|
if (clientExist) throw new Error('Client ID already exists.')
|
|
|
|
// Create a new client
|
|
const client = new Client({
|
|
clientid,
|
|
clientsecret
|
|
})
|
|
|
|
const savedClient = await client.save()
|
|
|
|
return {
|
|
clientid: savedClient.clientid,
|
|
clientsecret: savedClient.clientsecret
|
|
}
|
|
}
|