1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-10 19:34:34 +00:00
Files
server/src/controllers/createClient.ts
2021-11-02 18:42:06 +05:00

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
}
}